Vectorstore Qdrant Backend
The Qdrant backend: self-hosted on Kubernetes, or Qdrant Cloud.
See https://qdrant.tech/. A vectorstore is one Qdrant collection, with one dense vector per
chunk. Its text is in the payload’s page_content, and its metadata in metadata,
as LangChain’s QdrantVectorStore stores them, so that its collections stay readable.
Every operation is one of smarter.apps.vectorstore.execution’s. The texts are embedded here, in the app. A Qdrant
Cloud collection, at its ApiConnection’s url, is reached through the tool runner, in the tool worker (ADR-038); a
self-hosted server, which Smarter runs in the cluster, in process.
- class smarter.apps.vectorstore.backends.qdrant.QdrantBackend(vectorstore, embeddings=None, client=None, kubernetes=None)[source]
Bases:
SmarterVectorstoreBackendThe Qdrant backend.
- Parameters:
client (
QdrantClient|None) – A QdrantClient, e.g. an in-memory one in tests. By default it connects to the self-hosted server, or to the managed service of the vectorstore’s ApiConnection.kubernetes (
QdrantKubernetes|None) – The QdrantKubernetes of a self-hosted server. Created if needed.
- check_credentials()[source]
Check that Qdrant accepts the vectorstore’s credentials.
A self-hosted server’s api key is generated by Smarter, and the server doesn’t exist yet, so only Qdrant Cloud is asked.
- Return type:
- Returns:
What was found, for a person.
- Raises:
VectorStoreBackendCredentialsError – If Qdrant Cloud refuses the api key.
VectorStoreBackendConnectionError – If Qdrant Cloud can’t be reached.
- property client: QdrantClient
The Qdrant client of a self-hosted server, created when it is first used, or the one a test injected.
A self-hosted server is reached at its in-cluster endpoint, with its generated API key. A Qdrant Cloud collection has no client here: its operations go to the tool runner (
operation()).- Raises:
VectorStoreBackendError – For a Qdrant Cloud vectorstore without an injected client.
- create()[source]
Create the Qdrant collection, with a payload index on each chunk’s document id.
- Return type:
- create_snapshot(name)[source]
Take a snapshot of the collection, and wait for it.
- Parameters:
name (
str) – Unused: Qdrant names the snapshot.- Return type:
SnapshotInfo- Returns:
The snapshot’s name and size.
- Raises:
VectorStoreBackendError – If Qdrant did not create it.
- delete_document(document_id)[source]
Delete every chunk of a document, whatever their number.
- Return type:
- destroy()[source]
Delete the collection, or, if self-hosted, the whole Qdrant server and its volume.
The collection goes with the server’s volume.
- Return type:
- exists()[source]
Whether the Qdrant collection exists.
- Raises:
VectorStoreBackendCredentialsError – If Qdrant refuses the api key.
VectorStoreBackendConnectionError – If Qdrant is unreachable.
- Return type:
- infrastructure_conditions()[source]
The conditions of a self-hosted Qdrant server: its volume, then its pod.
Qdrant Cloud has none.
- Return type:
- Returns:
The
VolumeandServerconditions, or an empty list.
- property kubernetes: QdrantKubernetes
The Kubernetes resources of the self-hosted Qdrant server, created when it is first used.
- managed_url_and_api_key()[source]
The url and the api key of a Qdrant Cloud vectorstore’s ApiConnection, read here, in the app.
- operation(name, params=None, timeout=30)[source]
Run one of the collection’s operations: in process on a self-hosted server, or through the tool runner for Qdrant Cloud.
- provision()[source]
Create, or update, the Kubernetes resources of a self-hosted Qdrant server, without waiting for it.
Nothing is done for Qdrant Cloud.
- Raises:
VectorStoreBackendError – If a self-hosted vectorstore has no API key Secret.
- Return type:
- restore_snapshot(name)[source]
Recover the collection from a snapshot on the self-hosted server’s volume, and wait for it.
- search(query, k=4, search_type='similarity', score_threshold=None, fetch_k=None, lambda_mult=None, metadata_filter=None)[source]
Find the chunks that are closest in meaning to a query, embedded here.
- Parameters:
query (
str) – The query.k (
int) – How many results.search_type (
str) –similarity,similarity_score_threshold, ormmr(maximal marginal relevance).score_threshold (
float|None) – The lowest score of a result, forsimilarity_score_threshold.fetch_k (
int|None) – How many candidates MMR re-ranks. By default, four timesk, and at least 20.lambda_mult (
float|None) – MMR’s balance of relevance, 1, and diversity, 0. By default 0.5.metadata_filter (
dict[str,Any] |None) – Chunks whose metadata has these values, e.g.{"source": "faq"}.
- Return type:
list[SearchResult]- Returns:
The results. MMR’s have no score.
- stats()[source]
The collection’s exact vector count, status, segments count and indexed vectors count.