Skip to content

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.

open classmethod

open(path: str | Path) -> VectorStore

Open (creating if needed) a store at path.

close

close() -> None

Close the underlying SQLite connection.

__enter__

__enter__() -> VectorStore

Support with VectorStore.open(...) as store:.

__exit__

__exit__(*exc_info: object) -> None

Close the connection on context-manager exit.

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

space is not compatible with this store's already-bound space (see EmbeddingSpace.compatible_with).

add_many

add_many(
    entries: Sequence[VectorEntry], *, space: EmbeddingSpace
) -> None

Insert or replace several vectors in one transaction.

remove

remove(entry_id: str) -> None

Delete one entry; a no-op if it does not exist.

get

get(entry_id: str) -> VectorEntry | None

Look up one entry by id, or None.

count

count() -> int

How many entries this store holds.

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

space is not compatible with this store's bound space.

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.

compact

compact() -> None

Reclaim disk space after deletions (VACUUM).

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.query_and_rerank), optional otherwise.

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 [-1.0, 1.0]. Meaningful only within this store — never compared across stores or embedding spaces.

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 space.

required
query_text str

The query's original text — reranking scores text, not vectors.

required
space EmbeddingSpace

The embedding space query_vector was produced in; must be compatible with store's bound space (see VectorStore.query).

required
client AsyncClient

An anyinfer.AsyncClient to dispatch the rerank call through.

required
rerank_target str

The rerank target, e.g. "cohere:rerank-v3.5".

required
candidate_k int

How many coarse vector matches to hand to the reranker.

20
top_n int | None

Passed through to AsyncClient.rerank; None returns every candidate, reordered.

None

Raises:

Type Description
VectorStoreError

A candidate has no stored text — reranking needs text, and this package never invents it.

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.