mirror of
https://github.com/semantica-agi/semantica.git
synced 2026-09-10 04:00:35 +00:00
Compare commits
3
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
569da983a7 | ||
|
|
5c25c198f0 | ||
|
|
86f8b3907a |
+23
-15
@@ -84,13 +84,13 @@ icon: "rocket"
|
|||||||
# 1. Ingest
|
# 1. Ingest
|
||||||
sources = FileIngestor().ingest("data/report.pdf")
|
sources = FileIngestor().ingest("data/report.pdf")
|
||||||
|
|
||||||
# 2. Parse
|
# 2. Parse (extract_text returns a plain string for any supported format)
|
||||||
parsed = DocumentParser().parse(sources[0])
|
text = DocumentParser().extract_text(sources[0].path)
|
||||||
|
|
||||||
# 3. Extract
|
# 3. Extract (extractors take text, return Entity / Relation objects)
|
||||||
ner = NERExtractor(method="pattern") # no API key needed
|
ner = NERExtractor(method="pattern") # no API key needed
|
||||||
entities = ner.extract(parsed)
|
entities = ner.extract(text)
|
||||||
relationships = RelationExtractor().extract(parsed, entities=entities)
|
relationships = RelationExtractor(method="pattern").extract(text, entities=entities)
|
||||||
|
|
||||||
# 4. Build
|
# 4. Build
|
||||||
graph = GraphBuilder(merge_entities=True).build(
|
graph = GraphBuilder(merge_entities=True).build(
|
||||||
@@ -144,23 +144,31 @@ icon: "rocket"
|
|||||||
context = AgentContext(
|
context = AgentContext(
|
||||||
vector_store=VectorStore(backend="faiss", dimension=768),
|
vector_store=VectorStore(backend="faiss", dimension=768),
|
||||||
knowledge_graph=ContextGraph(advanced_analytics=True),
|
knowledge_graph=ContextGraph(advanced_analytics=True),
|
||||||
|
graph_expansion=True, # blend graph traversal into retrieval
|
||||||
|
max_expansion_hops=3, # how far to walk from the seed nodes
|
||||||
)
|
)
|
||||||
|
|
||||||
# Load your knowledge graph
|
# store() runs extraction and populates both the vector index and the graph
|
||||||
context.load_graph("company_kg.json")
|
context.store([
|
||||||
|
{"content": "Steve Wozniak co-founded Apple with Steve Jobs in 1976."},
|
||||||
|
{"content": "Tony Fadell led the iPod team at Apple, then founded Nest."},
|
||||||
|
])
|
||||||
|
|
||||||
# Multi-hop GraphRAG query
|
# GraphRAG retrieval: seed from vector matches, expand along graph edges
|
||||||
result = context.query(
|
results = context.retrieve(
|
||||||
"What companies were founded by people who worked at Apple?",
|
"What companies were founded by people who worked at Apple?",
|
||||||
mode="graphrag",
|
use_graph=True,
|
||||||
reasoning=True,
|
expand_graph=True,
|
||||||
)
|
)
|
||||||
|
for r in results:
|
||||||
# Every claim links back to a source node
|
print(f"[{r['score']:.3f}] {r['content'][:70]} (source: {r['source']})")
|
||||||
for claim in result.claims:
|
|
||||||
print(f"{claim.text} → source: {claim.source_node}")
|
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Each result carries `content`, `score`, `source`, and `metadata`. For a
|
||||||
|
grounded natural-language answer plus an auditable traversal, use
|
||||||
|
`context.query_with_reasoning(query, llm_provider=...)` — it returns
|
||||||
|
`response`, `reasoning_path`, `sources`, and `confidence`.
|
||||||
|
|
||||||
**Next:** [GraphRAG concepts →](/concepts#graphrag)
|
**Next:** [GraphRAG concepts →](/concepts#graphrag)
|
||||||
</Tab>
|
</Tab>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user