Open a session with an embedding model, add documents, ask questions.
The web index is process-wide. Opening a second session while one is open throws
invalidState with “A RAG session is already open. Close it before opening another”. No other SDK
has this constraint.
Opening
Omit llmModel for a retrieval-only session: search works, query does not.
RagSession
Ingesting a dropped file
Ingestion chunks, embeds, and indexes. It is the slow part, so do it once and keep the session
rather than re-ingesting per question. Show progress for anything larger than a page.
Retrieval without generation
Useful for showing sources, or for feeding matches into your own prompt.
Streaming an answer
Sources usually arrive before the first token, which is what lets you show what the answer is
based on while it is still being written.
Configuration
Overlap matters more than it looks. Without it, a sentence split across a chunk boundary is
retrievable from neither half.
Two models at once
A RAG session holds an embedding model and a language model. In a tab that is real memory
pressure, so prefer a small embedding model: all-minilm-l6-v2 is a fraction of the size of
the language model beside it.
Closing
Close before opening another, and close on pagehide. Because the index is process-wide, a
session you forget to close blocks every later one for the lifetime of the page.