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.

class smarter.apps.vectorstore.backends.base.SearchResult(id, text, metadata=<factory>, score=None)[source]

Bases: object

A chunk that a search found.

__init__(id, text, metadata=<factory>, score=None)
id: str | None
metadata: dict[str, Any]
score: float | None = None
text: str
class smarter.apps.vectorstore.backends.base.SmarterVectorstoreBackend(vectorstore, embeddings=None)[source]

Bases: ABC

Abstract base class of the vector database backends.

Parameters:
  • vectorstore (VectorstoreMeta) – The vectorstore.

  • embeddings (Embeddings | None) – Its embeddings model. Required for upsert() and search().

__init__(vectorstore, embeddings=None)[source]
abstractmethod create()[source]

Create the index or collection.

Return type:

None

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:

None

abstractmethod delete_snapshot(name)[source]

Delete a snapshot, or backup.

Return type:

None

destroy()[source]

Delete the index or collection, and any infrastructure that Smarter runs.

Return type:

None

abstractmethod drop()[source]

Delete the index or collection, and its data.

Return type:

None

property embeddings: Embeddings
abstractmethod exists()[source]

Whether the index or collection exists.

Return type:

bool

property index_name: str
infrastructure_ready()[source]

Whether the infrastructure that Smarter runs is ready, and why not.

A managed service always is.

Return type:

tuple[bool, str]

logs(tail=200)[source]

The database server’s logs, if Smarter runs it.

Return type:

str | None

provision()[source]

Create the database’s infrastructure, if Smarter runs it.

It returns without waiting for it.

Return type:

None

abstractmethod restore_snapshot(name)[source]

Replace the index or collection’s data with a snapshot’s.

Return type:

None

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.

Parameters:
  • search_type (str) – similarity, similarity_score_threshold, or mmr (maximal marginal relevance).

  • metadata_filter (dict[str, Any] | None) – chunks whose metadata has these values, e.g. {“source”: “faq”}.

Return type:

list[SearchResult]

abstractmethod stats()[source]

The database’s statistics.

It includes vector_count.

Return type:

dict[str, Any]

stop()[source]

Stop the infrastructure that Smarter runs, keeping its data.

Return type:

None

abstractmethod upsert(ids, texts, metadatas, batch_size=64)[source]

Embed and insert, or replace, chunks.

Return type:

None

class smarter.apps.vectorstore.backends.base.SnapshotInfo(name, size_bytes=None, ready=True)[source]

Bases: object

A Qdrant snapshot, or a Pinecone backup.

__init__(name, size_bytes=None, ready=True)
name: str
ready: bool = True
size_bytes: int | None = None
exception smarter.apps.vectorstore.backends.base.VectorStoreBackendConnectionError(message='')[source]

Bases: VectorStoreBackendError

The vector database cannot be reached.

exception smarter.apps.vectorstore.backends.base.VectorStoreBackendError(message='')[source]

Bases: SmarterException

A vector database operation failed.