mirror of
https://github.com/semantica-agi/semantica.git
synced 2026-08-29 04:26:20 +00:00
- Fix What's new → link in Info banner (now a proper <a> tag, always clickable) - Replace 4-stat CardGroup on index with inline premium stats row - Convert every <CardGroup>/<Card> block site-wide to markdown bullet lists: content sections → bold-title bullets with sub-bullets, nav cards → [Title](href) — description - Add cursor-animated list item hover effects to custom.css: green inset left border, subtle background tint, marker color change on hover - Affects index, getting-started, quickstart, concepts, modules, faq, architecture, installation, cookbook, glossary, learning-more, explorer-setup, cli-setup, community, contributing-guide, governance, citation, project-license, all integrations pages, and all 20+ reference module pages
12 KiB
12 KiB
title, description, icon
| title | description | icon |
|---|---|---|
| Seed Module | Bootstrap Knowledge Graphs from verified, structured sources: taxonomies, reference tables, product catalogs, and domain anchors. | database |
semantica.seed gives your knowledge graph a reliable, verified starting point:
- Load verified reference data first: ISO codes, employee rosters, product catalogs, domain taxonomies
SeedDataManagermerges freshly extracted data onto foundation nodes without creating duplicates- Supports JSON, CSV, and programmatic registration of seed sources
- Deterministic test graph generation from structured seed data
- Anchors entity extraction to known entities, reducing hallucination and duplicate nodes
Exported Classes
| Class | Role |
|---|---|
SeedDataManager |
Coordinator: register_source, load_source, create_foundation_graph, integrate_with_extracted |
SeedDataSource |
Config dataclass: {name, format, location, entity_type, verified, version, metadata} |
SeedData |
Container dataclass: {entities, relationships, properties, metadata} |
What You Get
- SeedDataManager — Register sources, build a foundation graph, validate quality, and merge with extracted data.
- SeedDataSource — Typed source definition supporting CSV, JSON, SQL, and API with format-specific config.
- Foundation Graph — Build a foundation graph from all registered sources in one pass, ready to merge with extracted data.
- Merge Strategies —
seed_first,extracted_first, andmergewith property-level conflict detection. - Validation — Required field checks, ID uniqueness, type consistency, reference integrity, and encoding validation before loading.
- Versioning — Track seed data versions across pipeline runs and diff changes between versions.
Quick Start
```python from semantica.seed import SeedDataManagermanager = SeedDataManager()
manager.register_source("countries", "csv", "data/countries.csv")
manager.register_source("taxonomy", "json", "data/taxonomy.json")
manager.register_source("employees", "csv", "data/employees.csv")
```
<Tip>
**Register all sources before calling `create_foundation_graph()`.** `create_foundation_graph()` processes all registered sources in one pass. Registering a source after calling it means that source is silently excluded. Register all sources at the start of your script, then call `create_foundation_graph()` once.
</Tip>
<Warning>
**Validate before loading.** `manager.validate_quality(seed_data)` catches missing required fields, type inconsistencies, and duplicate IDs before they corrupt your graph. Running validation after loading means you'll need to roll back. Validation is fast: always run it first.
</Warning>
extractor = NERExtractor(method="ml")
new_entities = extractor.extract("Apple Inc. partners with Microsoft Corp.")
# Merge with seed data - note the correct parameter names
final_kg = manager.integrate_with_extracted(
seed_data=foundation_kg,
extracted_data={"entities": new_entities, "relationships": []},
merge_strategy="merge"
)
```
<Warning>
**Load seed data before extracted data.** Seed data is your ground truth: normalised, curated, and already de-duplicated. Load it first with `create_foundation_graph()`, then merge extracted entities on top. Merging in the wrong order lets noisy extracted data overwrite trusted reference values.
</Warning>
SeedDataSource Types
```python from semantica.seed import SeedDataSource, SeedDataManagercsv_source = SeedDataSource(
name="employees",
format="csv",
location="data/employees.csv",
entity_type="Person",
verified=True,
metadata={"description": "Company employee list with titles and departments"}
)
manager = SeedDataManager()
manager.register_source(
"employees", "csv", "data/employees.csv", entity_type="Person", verified=True
)
```
manager.register_source(
"taxonomy", "json", "knowledge/taxonomy.json",
entity_type="Concept", relationship_type="subclass_of"
)
```
manager.register_source(
"geographic", "database", "postgresql://user:pass@host/geonames",
entity_type="Location", verified=False
)
```
manager.register_source(
"wikidata", "api", "https://wikidata.org/sparql",
entity_type="Entity"
)
```
SeedDataManager Reference
| Method | Description |
|---|---|
register_source(name, format, location, **config) |
Add a new data source to the manager |
load_source(source_name) |
Load and return raw data from a registered source |
create_foundation_graph() |
Build the initial graph from all registered sources |
integrate_with_extracted(seed_data, extracted_data, merge_strategy) |
Merge seed data with newly extracted entities/relationships |
validate_quality(seed_data) |
Check data integrity and return validation report |
export_seed_data(path, format) |
Save processed seed data to file |
Different strategies for resolving conflicts during integrate_with_extracted():
```python
final_kg = manager.integrate_with_extracted(
seed_data=foundation_kg,
extracted_data=new_data,
merge_strategy="seed_first"
)
```
Use when seed data is high-confidence and extraction is exploratory.
```python
final_kg = manager.integrate_with_extracted(
seed_data=foundation_kg,
extracted_data=new_data,
merge_strategy="extracted_first"
)
```
Use for rapid prototyping when extraction quality is known to be good.
```python
final_kg = manager.integrate_with_extracted(
seed_data=foundation_kg,
extracted_data=new_data,
merge_strategy="merge"
)
```
Use for production pipelines when both seed and extracted data are valuable.
Full Pipeline Example
from semantica.seed import SeedDataManager
from semantica.parse import DocumentParser
from semantica.split import TextSplitter
from semantica.semantic_extract import NERExtractor, RelationExtractor
# Initialize components
manager = SeedDataManager()
parser = DocumentParser()
splitter = TextSplitter(method="sentence", chunk_size=200)
ner = NERExtractor(method="ml")
rel_ext = RelationExtractor(method="ml")
# Register seed sources
manager.register_source("taxonomy", "json", "seeds/domain_taxonomy.json")
manager.register_source("entities", "csv", "seeds/known_entities.csv")
# Create foundation
foundation_kg = manager.create_foundation_graph()
print(f"Foundation: {len(foundation_kg['entities'])} entities, {len(foundation_kg['relationships'])} relationships")
# Process new document
parsed = parser.parse("research_paper.pdf")
chunks = splitter.split(parsed["full_text"])
# Extract from each chunk
all_entities = []
all_relations = []
for chunk in chunks:
entities = ner.extract(chunk.text)
relations = rel_ext.extract(chunk.text)
all_entities.extend(entities)
all_relations.extend(relations)
# Merge with foundation
extracted_data = {"entities": all_entities, "relationships": all_relations}
final_kg = manager.integrate_with_extracted(
seed_data=foundation_kg,
extracted_data=extracted_data,
merge_strategy="merge"
)
print(f"Final graph: {len(final_kg['entities'])} entities, {len(final_kg['relationships'])} relationships")
# Export for downstream use
manager.export_seed_data("output/enriched_kg.json", format="json")
YAML Configuration
Define sources in YAML for production deployments: no code changes needed to switch environments:
seed:
sources:
- name: "employees"
format: "csv"
location: "./data/employees.csv"
config:
id_column: "employee_id"
type: "Person"
- name: "taxonomy"
format: "json"
location: "./data/taxonomy.json"
- name: "products"
format: "sql"
location: "${DATABASE_URL}"
config:
query: "SELECT id, name, category FROM products WHERE active = true"
merge:
strategy: "merge"
validation:
strict: true
required_fields: ["id", "type"]
Environment variable overrides:
export SEMANTICA_SEED_DATA_DIR=./data/seed
export SEMANTICA_SEED_MERGE_STRATEGY=seed_first
- Ingest — Load unstructured data alongside seed data.
- Knowledge Graph — The target graph that seed data populates.
- Deduplication — Handle duplicates during seed-extracted merge.
- Pipeline — Incorporate seed loading as a named pipeline step.