Retrieval as code
Two common ways to answer over a corpus have drawbacks. Agentic retrieval-augmented generation (RAG) issues many retrieval calls and spends tokens stitching the results together. A coding agent that greps and parses raw files is flexible, but it’s slow and expensive, and its results are unreliable. A query turn does the hard retrieval work in one place. The model writes Python that reads artifacts, runs search, walks the graph, and queries structured tables, then answers from only the evidence it surfaced. Raw tool output never enters the model’s context.Query runtime
The Nexus runtime runs each query. It’s a single generic Python image that the orchestrator launches fresh for each turn, with no per-context code. Every context runs the same entrypoint, parameterized by its manifest.- Container: Each query starts one isolated container that runs that turn, then exits. It pulls the scoped contexts’ curated knowledge: artifacts on disk plus their vector index.
- Orientation: The runtime reads the manifests and an artifact outline up front, so the model starts knowing what knowledge exists and where.
- Agent loop: The model writes Python into a persistent read-eval-print loop (REPL) that calls the retrieval SDK to read artifacts, run searches, walk the graph, and query structured tables. The runtime posts each step as it happens, which powers the live answer stream. You can replay the full sequence for any query in its query trace.
- Answer: When the model can answer, it writes the answer with inline citations and ends the turn. The runtime then builds
citationsfrom what the loop retrieved and the files the answer names.
Agent loop
The model’s primary tool isrun_python, a persistent REPL. Variables carry over between calls, so in one block the model can find an artifact, read it, filter its sources, and pull a verbatim quote. It processes results in code and prints only what it needs.
For example, this block finds a summary artifact about acquisition terms, reads it, and searches that artifact’s sources for the purchase price:
Python
Retrieval SDK
The Composable Retriever, the Nexus component that serves artifacts to queries, loads these primitives into the REPL. The model reads artifacts off disk first because it’s cheapest, falls back to search over the index, and uses SQL for counts and enumerations.Read artifacts
Search
Structured tables
Answers and citations
The model writes the answer at the end of the agent loop. These rules shape what the answer draws on and how it cites sources.- Evidence: The model answers from the evidence its code surfaced rather than from whole documents, so it reasons over a small, relevant context.
- Citations: Each citation names its source file, plus the pages and sections of the passages it drew on when they’re available.
- Duplicate sources: When several sources contain the same content and the answer draws on one of them, the model is prompted to say which one it used and why. It’s also prompted to name each of the others by its full file name, so they’re cited too. If your question names the source, the answer uses it without listing the others. With more than five other copies, the answer gives their count instead.
- Earlier-turn citations: In a session, a follow-up answer can cite a file that an earlier turn retrieved, if the answer names it. These citations are file-level, so they include the
sourcebut no pages or sections. Theirgroundingiscarriedbecause the current turn didn’t retrieve the file itself. - Structured output: When a query includes a
shape, a second model call turns the answer into a document built to that schema. Nexus checks the document against the schema, and the model rewrites it up to two times if it breaks a rule, such as amaxLength. If it still doesn’t conform, the query returns the last version. The document’s values don’t include inline citation markers, and the sources are incitations.