Documents, a splitter cuts them into chunks, a vector store indexes the chunks with embeddings, and a retriever searches it, optionally with a reranker, at question time.
Documents
ADocument (gwenflow.types) holds content, metadata, and once indexed an embedding; a search result also has a score. Its id defaults to a hash of the content, so re-ingesting the same chunk keeps its identity.
Readers
They are importable from
gwenflow.readers. The PDF and Office readers need pip install "gwenflow[readers]".
SimpleDirectoryReader reads PDF and JSON files with their readers and other files as text. Its options: input_files instead of input_dir, exclude, exclude_hidden (default True), recursive (default True), required_exts, encoding, filename_as_id, raise_on_error.
Splitting
TokenTextSplitter cuts text into chunks of a number of tokens, with an overlap so a sentence cut at a boundary keeps its context:
The retriever
vector_db, the retriever creates a LanceDB table in ./<name> (or pathname), with Gwenlake embeddings (multilingual-e5-large) and the Gwenlake reranker (BAAI/bge-reranker-v2-m3). This default needs pip install lancedb and a GWENLAKE_API_KEY. search fetches ten times top_k candidates, and returns the best top_k.
In an agent
Withretriever=, the agent searches it with the task before each run and puts the passages in its system prompt, as references.
As a tool
To let the model decide when and what to search, give it aRetrieverTool instead:
Vector stores
Each takes
embeddings and an optional reranker, and offers insert(documents), search(query, limit, filters), get(id), delete(id), count() and drop(). Pass one to the retriever:
Embeddings and reranking
GwenlakeEmbeddings and GwenlakeReranker call the Gwenlake API (GWENLAKE_API_KEY). To use another provider, subclass gwenflow.embeddings.Embeddings (implement embed_documents(texts) and embed_query(text)) or gwenflow.reranker.Reranker (implement rerank(query, documents)).
For keyword search without embeddings, BM25(documents).rank(query, top_n=5) (gwenflow.retriever) ranks documents with BM25.