aaa.vector¶
VectorStore ¶
Bases: Protocol
Anything that stores vectors with a payload and finds the nearest ones.
namespaceis a hard partition: records in one namespace are invisible to queries in another.filternarrows by metadata (seeaaa.vector.filters); a store that cannot express a filter raisesUnsupportedFilter.dimensionmay beNoneuntil the first upsert; after that every vector must match it (DimensionMismatch).
EmbeddingIndex ¶
EmbeddingIndex(
store: VectorStore,
embedder: Embedder,
*,
namespace: str | None = None,
max_overfetch: int = 1000,
)
EmbeddingIndex(PgVectorStore(...), LLMEmbedder(client)).
search(query, filter=...) takes either a Filter / dict (evaluated by the store) or, for compatibility with InMemoryIndex,
a Python predicate over the Doc. A predicate cannot be pushed down, so the index fetches more candidates and keeps asking until
it has k survivors or the store is exhausted (bounded by max_overfetch); prefer a Filter on a large index.
TenantVectorStore ¶
A view of a store for ONE tenant, safe to hand to code that handles that tenant's requests.
Two independent walls: every call is pinned to the namespace <prefix><tenant> (a hard partition), AND every record carries
meta["tenant"] and every query/delete is ANDed with tenant == <tenant> outside whatever filter the caller passes, so an or in
the caller's filter cannot reach another tenant's rows. Passing a different namespace, or a record claiming another tenant, is an error.
Record
dataclass
¶
Match
dataclass
¶
Match(
id: str,
score: float,
text: str = "",
meta: dict[str, Any] = dict(),
vector: list[float] | None = None,
)
One search result. score is a similarity for cosine and dot (higher is better) and a distance for euclidean
(lower is better); see VectorStore.higher_is_better. Scores from different stores or metrics are not comparable.
Filter ¶
parse
staticmethod
¶
Accept a Filter, or a dict: {"lang": "en", "year": {"$gte": 2020}, "tag": {"$in": ["a"]}, "$or": [{...}, {...}]}.
InMemoryVectorStore ¶
PgVectorStore ¶
PgVectorStore(
dsn: str | None = None,
*,
pool: Any = None,
dimension: int,
metric: Metric = "cosine",
table: str = "aaa_vectors",
hnsw: bool = True,
ef_search: int = 100,
)
QdrantStore ¶
QdrantStore(
*,
dimension: int,
collection: str = "aaa_vectors",
metric: Metric = "cosine",
client: Any = None,
**client_kwargs: Any,
)
LLMReranker ¶
Listwise rerank with any LLMClient: the model sees the query and numbered passages and returns the best order.
Unreadable replies keep the original order (reranking is an improvement, never a failure).
RerankingIndex ¶
RerankingIndex(index, reranker, fetch_k=30): retrieve fetch_k, return the reranker's best k. Scores of the returned hits
are the first-stage scores (the reranker's own are not comparable to them).
SqliteVecStore ¶
SqliteVecStore(
path: str = ":memory:",
*,
dimension: int,
metric: Metric = "cosine",
table: str = "aaa_vectors",
)
LanceDBStore ¶
LanceDBStore(
uri: str = "./lancedb",
*,
dimension: int,
metric: Metric = "cosine",
table: str = "aaa_vectors",
storage_options: dict[str, str] | None = None,
initial_batch: int = 64,
)
ChromaStore ¶
ChromaStore(
*,
dimension: int,
metric: Metric = "cosine",
path: str | None = None,
host: str | None = None,
port: int = 8000,
client: Any = None,
prefix: str = "aaa",
)
PineconeStore ¶
PineconeStore(
*,
dimension: int,
api_key: str | None = None,
index_name: str | None = None,
index_host: str | None = None,
metric: Metric = "cosine",
create: bool = False,
cloud: str = "aws",
region: str = "us-east-1",
consistent: bool = True,
consistency_timeout_s: float = 30.0,
control_host: str | None = None,
client: Any = None,
)
setup
async
¶
Create the index if create=True and it does not exist yet (needs the control plane and a matching SDK/API version).
CohereReranker ¶
CohereReranker(
api_key: str | None = None,
*,
model: str = "rerank-v4.0-pro",
base_url: str = "https://api.cohere.com",
timeout_s: float = 20.0,
transport: Any = None,
)
Cohere's rerank endpoint (POST https://api.cohere.com/v2/rerank; plain HTTP, no SDK). The passages leave your process.
RerankingIndex(index, CohereReranker(api_key="...", model="rerank-v4.0-pro"), fetch_k=30)
Built from Cohere's published request/response description and tested with a mock transport; not run against a live account.