Retrieval over your own documents
One call builds the index; the answer comes back with the source it used.
The program, and what it printed
This ran against effGen with gemini:gemini-3.1-flash-lite. The pane under the code is that run’s output, pasted — so where the answer depends on a live API or on the model’s wording, yours will differ. The pane is the shape that run actually had, not a tidied one.
from pathlib import Path
from effgen.presets import create_agent
Path("handbook.md").write_text(
"# Support handbook\n\n"
"Refunds are issued within 14 days of purchase.\n"
"Priority support answers within 4 business hours.\n"
"The free tier allows 60 API requests an hour.\n"
)
agent = create_agent(
"rag",
"gemini:gemini-3.1-flash-lite",
knowledge_base="handbook.md",
)
response = agent.run("How long do I have to ask for a refund?")
print(response.text)
print()
for citation in response.citations:
print(f"[{citation.index}] {citation.source} score={citation.relevance_score}")You are eligible to request a refund within 14 days of your purchase [1]. [1] handbook.md score=0.7
What it does
create_agent("rag", model, knowledge_base=...) ingests the path you give it and wires a retrieval tool over it. Retrieval is hybrid — dense embeddings and BM25 — and the answer carries inline markers backed by response.citations, each naming the source and its relevance score. Ask it something the documents do not cover and it says so rather than inventing an answer.
What the run shows
- The preset refuses to build without a knowledge base, rather than succeeding over zero documents. Leave the argument out and it names the argument it needs.
- The [1] in the answer is backed by a Citation object: the source file, the chunk, the score and, for a PDF, the page.
- Ingestion reports what it skipped and why — a corrupt file, an empty one, a duplicate, an unsupported extension each have their own reason.
The full script
The program above is the short version. The one in the repository at examples/web_retrieval/retrieval_agent.py covers more cases and takes a --model flag. It ships with the package, so it runs from the command line without cloning anything:
effgen examples run web_retrieval/retrieval_agentRead it on GitHub