Vector Store Add-On¶
anyinfer_store: a small-scale, single-process, embedded vector store; a separate
installable distribution, never imported by anyinfer core and never a dependency of it.
See the vector store guide for the full walkthrough and the
explicit, permanent scale boundary this package commits to.
from anyinfer_store import VectorStore, query_and_rerank
anyinfer_store.VectorStore ¶
VectorStore(connection: Connection)
A single SQLite file holding one embedding space's worth of vectors.
Every entry in one store must share a compatible anyinfer.EmbeddingSpace — checked
with EmbeddingSpace.compatible_with, the identical rule anyinfer core's own routing
applies for a fallback target — so a query can never silently compare vectors that
were never comparable to begin with. The space is fixed the first time an entry is
added and stored permanently in the file; open the same file again later and it's
already there, no re-declaration needed.
space
property
¶
space: EmbeddingSpace | None
The embedding space this store is bound to, or None if still empty.
add ¶
add(
entry_id: str,
vector: Sequence[float],
*,
space: EmbeddingSpace,
metadata: Mapping[str, str] | None = None,
text: str | None = None,
) -> None
Insert or replace one vector.
Raises:
| Type | Description |
|---|---|
EmbeddingSpaceMismatchError
|
|
add_many ¶
add_many(
entries: Sequence[VectorEntry], *, space: EmbeddingSpace
) -> None
Insert or replace several vectors in one transaction.
query ¶
query(
vector: Sequence[float],
*,
space: EmbeddingSpace,
top_k: int = 10,
metadata_filter: Mapping[str, str] | None = None,
) -> list[QueryResult]
Brute-force top-k cosine similarity search.
Raises:
| Type | Description |
|---|---|
EmbeddingSpaceMismatchError
|
|
VectorStoreError
|
The store is empty (no space bound yet). |
rebuild_index ¶
rebuild_index() -> None
No-op for the brute-force backend; present so a future approximate-index backend can share this interface without a caller-visible change.
export_jsonl ¶
export_jsonl(path: str | Path) -> None
Write every entry, one JSON object per line, plus a header line with the space.
import_jsonl ¶
import_jsonl(path: str | Path) -> None
Load entries previously written by export_jsonl, into this (possibly
already-open, possibly empty) store.
anyinfer_store.VectorEntry
dataclass
¶
VectorEntry(
id: str,
vector: tuple[float, ...],
metadata: Mapping[str, str] = dict(),
text: str | None = None,
)
One stored vector.
Attributes:
| Name | Type | Description |
|---|---|---|
id |
str
|
Caller-supplied identifier, unique within one store. |
vector |
tuple[float, ...]
|
The embedding vector's components. |
metadata |
Mapping[str, str]
|
Small caller-supplied key/value payload, exact-match filterable. |
text |
str | None
|
The source text, when the caller chose to keep it — needed for a
second-stage rerank pass ( |
anyinfer_store.QueryResult
dataclass
¶
QueryResult(entry: VectorEntry, score: float)
One ranked match from VectorStore.query.
Attributes:
| Name | Type | Description |
|---|---|---|
entry |
VectorEntry
|
The matched entry. |
score |
float
|
Cosine similarity to the query vector, in |
anyinfer_store.query_and_rerank
async
¶
query_and_rerank(
store: VectorStore,
query_vector: list[float],
query_text: str,
*,
space: EmbeddingSpace,
client: AsyncClient,
rerank_target: str,
candidate_k: int = 20,
top_n: int | None = None,
) -> tuple[RankedItem, ...]
Coarse vector search, then a real rerank pass over its candidates.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
store
|
VectorStore
|
The store to search. |
required |
query_vector
|
list[float]
|
The query's embedding, in |
required |
query_text
|
str
|
The query's original text — reranking scores text, not vectors. |
required |
space
|
EmbeddingSpace
|
The embedding space |
required |
client
|
AsyncClient
|
An |
required |
rerank_target
|
str
|
The rerank target, e.g. |
required |
candidate_k
|
int
|
How many coarse vector matches to hand to the reranker. |
20
|
top_n
|
int | None
|
Passed through to |
None
|
Raises:
| Type | Description |
|---|---|
VectorStoreError
|
A candidate has no stored |
anyinfer_store.SIZE_WARNING_THRESHOLD
module-attribute
¶
SIZE_WARNING_THRESHOLD = 200000
Entry count past which VectorStore.add/add_many warn that brute-force search may be
noticeably slow — a signal, not a hard limit; nothing stops working at this count.
anyinfer_store.VectorStoreError ¶
Bases: Exception
Base class for every error this package raises.
anyinfer_store.EmbeddingSpaceMismatchError ¶
Bases: VectorStoreError
A vector was added or queried against a store bound to a different embedding space.
The same cross-space safety rule anyinfer's own routing applies, extended to
persistence: a wrong-but-plausible vector comparison fails loudly rather than
returning a confident-looking, meaningless result.