Repository navigation
Retrieval
kb.retrieve() is the RAG entry point. It returns the facts relevant to a question, as
notation, within a token budget.
context = kb.retrieve(
"Who is Google's CEO?",
top_k=5,
hops=1,
max_tokens=200,
format="notation",
)-
Vector search. The question is embedded and compared with the embedded facts. The
top_kclosest facts are the seeds. -
Graph expansion. Starting from the entities in those facts, Noema walks outward up to
hopsrelation edges. Each entity records its distance from the nearest seed. -
Assembly. Facts are packed greedily until
max_tokensis reached, in priority order: facts that directly matched the question first, then other facts closest to a seed.
The fact index is built on the first retrieve() and rebuilt after each ingest(). A loaded
bundle reuses its saved index.
| Option | Default | Meaning |
|---|---|---|
top_k |
5 |
Number of vector-search hits used as seeds |
hops |
1 |
How far to expand from each seed through the graph |
max_tokens |
200 |
Token budget for the returned text |
format |
"notation" |
"notation" for compact text, "natural_language" for decoded sentences |
token_model |
cl100k_base |
tiktoken encoding used to count the budget |
Any other format value raises ValueError.
retrieve() returns a RetrievalResult:
| Field | Meaning |
|---|---|
text |
The context, in the requested format. Empty when nothing was found |
notation |
The raw notation, whatever format was |
entity_ids, relation_ids
|
Which graph items made it into the text |
token_count |
Tokens used |
truncated |
True when the budget cut facts off |
fact_matches |
The vector-search hits, each with a relation_id and similarity score
|
-
Answers missing from the context. Raise
top_k, thenmax_tokens. Checktruncated: if it isTrue, the budget is cutting facts. -
Multi-hop questions. A question like "Who founded the company that acquired X?" needs a
fact from one document and a fact from another. Use
hops=2so expansion reaches the second fact. This is where graph retrieval differs from chunk retrieval. -
Noisy context. Lower
hopsandtop_k, or lowermax_tokens. -
Cost. Larger
max_tokensandhopssend more tokens. Fewer tokens per query is the point of Noema, so raise them only as far as accuracy needs.
Assembly stops at the first fact that would exceed the budget instead of searching for a smaller one that fits, so a budget slightly below a fact's size can end the context early.
format="notation" is the most token-efficient. format="natural_language" decodes the same
facts into sentences. The decoder is template-based, so the sentences can be grammatically rough,
but some models and downstream steps handle prose more reliably. Try both on your task.
context = kb.retrieve(question, max_tokens=200)
prompt = f"Use these facts:\n{context.text}\n\nQuestion: {question}"Check context.text for emptiness before calling your model, so you can answer "no information"
instead of prompting with nothing.
noema query company_kb.noema "Who is Google's CEO?" --top-k 5 --hops 1 --max-tokens 200