Skip to content

Transactional document and vector search

SharedData.SearchIndex.SearchIndex adds generic retrieval to the public SharedData.SQLite.SQLite container. Applications supply text, metadata and any embeddings. The SDK makes no model calls and does not decide ontology meaning, entity identities, business definitions or claim conflict policies.

Install shareddata[search] for vector support. Text search uses SQLite FTS5. Python 3.11 and 3.12 are supported by the SDK.

from pathlib import Path
from SharedData.SQLite import SQLite
from SharedData.SearchIndex import SearchIndex

container = SQLite("Hashs", "RT", "EXAMPLE", "DOCUMENTS",
                   root=Path("./example-storage"), private=True)
index = SearchIndex(container, namespace="articles")
index.put([{"key": "article-1", "text": "Reported quarterly revenue",
            "metadata": {"kind": "article"}}])
print(index.search("revenue", metadata={"kind": "article"}))

For supplied embeddings, open the same namespace with dimensions and an explicit model identifier. Put rows with a vector field and pass a query vector to search. The SDK checks dimensions, finite values and nonzero cosine vectors. Model identifiers define independent spaces; changing a model's dimensions requires a new identifier. Queries combine FTS5 BM25 and exact SIMD cosine kNN with reciprocal rank fusion. This is exact nearest-neighbor search, not HNSW or another approximate index.

Metadata equality filters apply before ranking and top-k selection. Namespace isolation is an application storage boundary; applications must authenticate and authorize their callers before selecting a container or namespace.

put and delete update document rows, text postings and vectors transactionally. Changed text invalidates embeddings from every old model space. Unchanged text without a new vector preserves valid embeddings. An outer application transaction can pass connection=db to either operation to commit its domain state and search index together. Create the index before opening that outer transaction.

stats() returns document and vector-space counts. create=False reopens an existing index without initializing one. SQLite owns persistence, connections and backup; this optional path does not change the memory-mapped record/index locking contract.