Retrieval-Augmented Generation (RAG) is a technique to ground LLM responses in your own data. Standard RAG retrieves documents based on Vector Similarity.
Graph RAG goes a step further: it retrieves documents based on Relationships.
Imagine you are searching a knowledge base for “Project Apollo”.
Relationships (Parent/Child, See Also, Citations) are critical for understanding context.
UnifyWeaver’s Python target implements a Hybrid Graph RAG:
links table) to find neighbors (Parents, Children).semantic_search(Query, TopK, Results): Standard Vector Search.graph_search(Query, TopK, Hops, Results): Graph RAG.The PtCrawler automatically extracts links from rdf:resource attributes (common in RDF/XML).
index_data :-
crawler_run(['data.rdf'], 1). % Crawl depth 1
This populates the links table in data.db:
| Source ID | Target ID |
|———–|———–|
| Child | Parent |
| Page A | Page B |
Use graph_search/4 to retrieve the context.
search_topic(Topic, Results) :-
% Find top 3 matches, then expand 1 hop (parents/children)
graph_search(Topic, 3, 1, Results).
Pass the structured results to the LLM.
summarize(Topic, Summary) :-
graph_search(Topic, 3, 1, Context),
Prompt = 'Summarize the topic using the provided context.',
llm_ask(Prompt, Context, Summary).
In our context/PT dataset (Pearltrees export):
The compiler translates graph_search into:
_get_runtime().searcher.graph_search(query, top_k=3, hops=1)
The runtime (PtSearcher) executes the following SQL logic:
SELECT id FROM embeddings ... (Vector Search)SELECT target_id FROM links WHERE source_id IN (ids) (Parents)SELECT source_id FROM links WHERE target_id IN (ids) (Children)focus, parents, and children.| ← Previous: Chapter 1: The Python Semantic Target | 📖 Book 13: Semantic Search | Next: Chapter 3: The Semantic Data Pipeline → |