Vectorstore Backend Base Class
The interface of vector database backends.
A backend runs one vectorstore’s database operations: its lifecycle, its data, and its dumps.
Lifecycle, status and scheduling are the job of
VectorstoreService, which calls a backend.
- smarter.apps.vectorstore.backends.base.DEFAULT_MMR_LAMBDA = 0.5
MMR’s balance of relevance, 1, and diversity, 0, unless a search names its own.
- class smarter.apps.vectorstore.backends.base.SearchResult(id, text, metadata=dict(), score=None)[source]
Bases:
objectA chunk that a search found.
- __init__(id, text, metadata=<factory>, score=None)
- text: str
- class smarter.apps.vectorstore.backends.base.SmarterVectorstoreBackend(vectorstore, embeddings=None)[source]
Bases:
ABCAbstract base class of the vector database backends.
- Parameters:
vectorstore (
VectorstoreMeta) – The vectorstore.embeddings (
Embeddings|None) – Its embeddings model. Required forupsert()andsearch().
- __init__(vectorstore, embeddings=None)[source]
- check_credentials()[source]
Check, quickly, that the database accepts the vectorstore’s credentials.
By default it asks whether the index exists, which a managed service answers only with a valid api key.
- Return type:
- Returns:
What was found, for a person.
- Raises:
VectorStoreBackendCredentialsError – If the database refuses them.
VectorStoreBackendConnectionError – If the database can’t be reached, which may pass.
- abstractmethod create_snapshot(name)[source]
Take a snapshot, or backup.
- Return type:
SnapshotInfo
- abstractmethod delete(ids)[source]
Delete chunks.
Ids that do not exist are ignored.
- Return type:
- destroy()[source]
Delete the index or collection, and any infrastructure that Smarter runs.
- Return type:
- property embeddings: Embeddings
The embeddings model, which turns texts into vectors.
- Raises:
VectorStoreBackendError – If the backend was created without one.
- property index_name: str
the vectorstore’s
index_name, or its default.- Type:
The name of the index or collection
- index_ready()[source]
Whether the index or collection, which exists, is ready to use, and why not.
By default it is as soon as it exists. Pinecone initializes a new index for a minute or two.
- infrastructure_conditions()[source]
The conditions of the infrastructure that Smarter runs, e.g. a self-hosted server’s volume and pod.
A managed service has none.
- Return type:
- Returns:
One condition per part of the infrastructure, in the order that they become ready.
- infrastructure_ready()[source]
Whether the infrastructure that Smarter runs is ready, and why not.
A managed service always is.
- provision()[source]
Create the database’s infrastructure, if Smarter runs it.
It returns without waiting for it.
- Return type:
- abstractmethod restore_snapshot(name)[source]
Replace the index or collection’s data with a snapshot’s.
- Return type:
- abstractmethod 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.
- abstractmethod stats()[source]
The database’s statistics.
It includes vector_count.
- abstractmethod upsert(ids, texts, metadatas, batch_size=64)[source]
Embed and insert, or replace, chunks.
- class smarter.apps.vectorstore.backends.base.SnapshotInfo(name, size_bytes=None, ready=True)[source]
Bases:
objectA Qdrant snapshot, or a Pinecone backup.
- __init__(name, size_bytes=None, ready=True)
- name: str
- ready: bool = True
- exception smarter.apps.vectorstore.backends.base.VectorStoreBackendConnectionError(message='')[source]
Bases:
VectorStoreBackendErrorThe vector database cannot be reached.
- exception smarter.apps.vectorstore.backends.base.VectorStoreBackendCredentialsError(message='')[source]
Bases:
VectorStoreBackendRejectedErrorThe vector database refused the api key, or there is none to send.
- exception smarter.apps.vectorstore.backends.base.VectorStoreBackendError(message='')[source]
Bases:
SmarterExceptionA vector database operation failed.
- exception smarter.apps.vectorstore.backends.base.VectorStoreBackendRejectedError(message='')[source]
Bases:
VectorStoreBackendErrorThe vector database refused a request, and would refuse it again, e.g. an invalid dimension or a full quota.
A deploy that meets it fails at once, rather than retrying.
- smarter.apps.vectorstore.backends.base.json_dict(value)[source]
An operation’s result that is a JSON object, as a dict; anything else, an empty one.
- smarter.apps.vectorstore.backends.base.json_dicts(value)[source]
An operation’s result that is a list of JSON objects, e.g. a query’s matches; anything else, an empty list.
- smarter.apps.vectorstore.backends.base.json_int(value)[source]
An operation’s result that is an integer, e.g. a snapshot’s size; anything else, None.
- smarter.apps.vectorstore.backends.base.mmr_fetch_k(k, fetch_k)[source]
How many candidates MMR re-ranks:
fetch_k, or four timeskand at least 20.- Return type:
- smarter.apps.vectorstore.backends.base.result_of(match, score)[source]
Return a database’s match as a search result.