Core
Concepts
Six ideas explain the whole platform. They are ordered the way a document travels: from an account, to a passage, to an answer.
Tenant
Every key belongs to one tenant. A tenant is the boundary for everything else: its documents, its index, its conversations and its quota. Two tenants can index a file with the same name and never see each other's passages.
This boundary is why a key is the only credential you need: there is no separate account id to pass, and no request can reach outside the tenant the key was issued for.
Chunk
A document is never searched whole. It is split into passages of at most 8 000 characters, with 500 characters of overlap between consecutive passages so a sentence cut in two still appears intact in one of them.
Section headings are preserved when the source has them: the splitter prefers to break at a heading rather than mid-paragraph, which keeps a passage about one topic instead of three.
A chunk is what gets cited. When an answer lists a source, it names the document the chunk came from. If the same document answers two questions differently, the chunks used are different: usually a sign the document needs restructuring, not that the model is wrong. Two different answers to ONE question are a different matter: that is retrieval deciding between passages, and the scores in the final event tell which passage won.
The path from an upload to a searchable passage:
Both indexes are built from the same passages. One finds a passage by meaning, the other by the words it contains: which is why an exact product code still matches even when its surrounding sentence says nothing distinctive.
The retrieval pipeline
Five stages run on every question, in order. The whole pipeline is bounded by three numbers: 60 retrieved, 40 reranked, 20 returned.
- The question is read two ways. Once as meaning, once as words. Both searches run at the same time rather than one after the other, each asking the index for 60 passages.
- The two result sets are merged and deduplicated. A passage found by both searches appears once. The union is capped at 40: reranking is the most expensive stage per pair, and a passage that both searches place low is almost never promoted by reading it closer: so scoring it is wasted work.
- The survivors are rescored against the question. The first stage compares a question to a passage in the abstract; the reranker reads the pair together and judges whether this passage actually answers this question.
- The top 20 become the context. They are capped by a character budget so a set of long passages cannot overflow the model's window.
All three numbers come from configuration (RETRIEVAL_TOP_K, RERANK_TOP_K),
so they can be tuned per deployment without touching the code.
Every stage reports its own duration in the final event, so a slow answer can be attributed to retrieval or to generation rather than guessed at.
Why reranking matters
The first stage is fast and approximate: it can only say that two texts are about similar things. That is enough to narrow thousands of passages to a few dozen, and not enough to order them.
Reranking reads the question and each candidate side by side and scores the pair. The difference shows up exactly where keyword overlap misleads: a question about cancellation retrieves passages about termination and refunds, because those words co-occur; the reranker keeps the one that answers the question asked.
Measured effect: without reranking the correct passage is often in the set but not in the top three, and the answer cites a neighbouring topic instead.
Streaming
The chat endpoint returns a stream rather than a complete document. The connection opens immediately, fragments arrive as the answer is generated, and a final event carries the sources and the per-stage timings.
This shape exists because waiting for a complete answer costs seconds of blank screen. It has one consequence worth designing around: the HTTP status is sent before generation starts. A quota error arrives on the stream, as an error event, not as a status code: a client that only checks the status will read an empty answer as a successful one.
A fragment can split a word, a sentence or a citation marker. Assemble the fragments and render the assembled text; do not format each fragment as if it were a complete sentence.
Sessions and history
Passing a session id continues a conversation. The six most recent messages of that session are given to the model as context, and the exchange is stored under the same id. Omit it and every request starts fresh.
History affects wording, not grounding. The passages retrieved still come from the corpus for each question: a follow-up like "and the notice period?" retrieves on its own terms, with the previous messages only helping the model interpret the ellipsis.
That separation is deliberate: a conversation cannot drift into answering from what it said earlier rather than from what the documents say. If a follow-up needs the earlier subject to retrieve anything, restate it.
