fastrag.vector_store.opensearch#
Async OpenSearch storage with BM25 and dense k-NN search over one index.
Uses OpenSearch’s REST API through the SDK’s existing httpx dependency. Lucene HNSW requires the k-NN plugin; OpenSearch 2.12+ supports the 4096-dimensional embeddings used by the chatbot example. Fusion happens in the SDK, so no server search pipeline or fusion plugin is required.
Module Attributes
Hits per |
Classes
|
Persist and search documents in an OpenSearch index. |
- fastrag.vector_store.opensearch.ID_PAGE_SIZE = 10000#
Hits per
_searchpage inOpenSearchVectorStore.all_ids(), the defaultindex.max_result_window.
- class fastrag.vector_store.opensearch.OpenSearchVectorStore(*, url, index='fastrag_documents', user=None, password=None, timeout=30.0, policy=None)[source]#
Bases:
VectorStore,LexicalStorePersist and search documents in an OpenSearch index.
filteris a JSON-encoded Query DSL object, e.g.'{"term": {"source_uri": "https://example.org/docs"}}'. Metadata is retained in_sourcewithout dynamic indexing. HTTPS uses username and password authentication with TLS certificate verification disabled.- Parameters:
- async ensure_ready(dimension)[source]#
Create the index or validate its existing vector and text mappings.
- Parameters:
dimension (int)
- Return type:
None
- async all_ids()[source]#
Page through every id sorted on the
idkeyword, withsearch_after.Returns an empty set when the index does not exist yet.
- async search(embedding, *, k, filter=None)[source]#
Search dense vectors with cosine similarity and optional native filter.
- async lexical_search(query, *, k, filter=None)[source]#
Search the analyzed content field using BM25.
- save(upstream, *, skip_existing=False)#
Return a lazy terminal step that indexes
upstream’s documents.Constructing the returned step performs no I/O — evaluating it (
async for document in vector_store.save(upstream):or.run()) is what upserts. Each document is queued into a batcher that checksexisting_ids()and flushes toupsert()onceself.policy.batch_sizedocuments have queued, or after a short window; every document is yielded back once its batch is resolved, withcachedset to whether the store already held it, andDocumentSavedemitted for it.- Parameters:
upstream (PipelineStep[Document]) – Final upstream step yielding embedded documents.
skip_existing (bool) – For an identity-preserving Embedder, check destination ids before embedding. Indexed items bypass vector retrieval and produce cached DocumentEmbedded and DocumentSaved events. Cached events and results may contain only identity/metadata with empty content and no vectors. Custom content filters disable header projection. Use a separate destination for each embedding configuration.
- Return type:
Either way,
recreate_cache(on the store’s policy or the pipeline’s) skips the existence check and upserts every document.
- sync(upstream, *, skip_existing=False)#
Like
save(), then delete every stored documentupstreamdid not yield.After a clean run the store holds exactly the documents the run produced: documents whose source disappeared or changed (a changed chunk gets a new id) are removed. Deletion happens once the upstream is exhausted, so a run that raises or is stopped early deletes nothing. A run with any
ItemFaileddeletes nothing either: a failed item’s documents are missing from the run, not from the source. Either way aDocumentsPrunedevent reports the outcome.The run must cover everything the store should keep — use one store (collection/index) per synced pipeline.
- Parameters:
upstream (PipelineStep[Document]) – Final upstream step yielding embedded documents.
- Return type: