Vectorstore Backend Base Class

Base class for vector store backends.

This class defines the interface that all vectorstore backends must implement. It includes methods for creating, deleting, upserting, querying, and getting stats for vector databases. Each backend should inherit from this class and provide concrete implementations for these methods based on the specific vector store being used (e.g., Pinecone, Weaviate, etc.).

class smarter.apps.vectorstore.backends.base.SmarterVectorstoreBackend(*args, db, embeddings=None, vector_store=None, **kwargs)[source]

Bases: ABC, SmarterHelperMixin

Abstract base class for vector store backends.

This class defines the service interface that all vector store backends must implement. All concrete backends (e.g., Pinecone, Weaviate, etc.) should inherit from this class and provide implementations for all abstract methods. The backend is responsible for managing the connection, storing and retrieving vectors, and handling database operations.

Parameters:
  • db (VectorestoreMeta) – The vector database instance to use.

  • embeddings (Optional[Embeddings], optional) – The embeddings model to use for vectorization (default is None).

  • vector_store (Optional[VectorStore], optional) – The vector store object (default is None).

add_documents(documents, embeddings)[source]

Add documents with their corresponding embeddings to the vector store.

initialize()[source]

Initialize the backend, setting up any necessary connections or configurations.

create()[source]

Provision a new vector database in the backend.

delete()[source]

Delete the vector database from the backend.

upsert(vectors)

Upsert vectors into the vector database in the backend.

query(query_vector, top_k=10)[source]

Query the vector database in the backend.

connect()[source]

Establish a connection to the vector database in the backend.

disconnect()[source]

Disconnect from the vector database in the backend.

load(embeddings)

Load vectors into the vector database from a list of embeddings.

Properties()
----------
index_stats : str

Get statistics about the vector database in the backend.

vector_store : object

Get the vector store object for the backend.

embeddings : Embeddings

Get the embeddings model.

connection : VectorStoreBackendConnection

Get or establish the connection to the vector database in the backend.

is_connected : bool

Check if there is an active connection to the vector database in the backend.

ready : bool

Check if the backend is ready for operations.

__init__(*args, db, embeddings=None, vector_store=None, **kwargs)[source]
abstractmethod add_documents(documents, embeddings)[source]

Add documents with their corresponding embeddings to the vector store.

Return type:

bool

abstractmethod connect()[source]

Establish a connection to the vector database in the backend.

Return type:

VectorStoreBackendConnection

property connection: VectorStoreBackendConnection

Get the connection to the vector database in the backend, establishing it if it doesn’t already exist.

abstractmethod create()[source]

Provision a new vector database in the backend.

db: VectorestoreMeta
abstractmethod delete()[source]

Delete the vector database from the backend.

abstractmethod disconnect()[source]

Disconnect from the vector database in the backend.

Return type:

None

property embeddings: Embeddings

Get the embeddings.

property index_stats: str

Get statistics about the vector database in the backend.

abstractmethod initialize()[source]

Initialize the backend, setting up any necessary connections or configurations.

property is_connected: bool

Check if there is an active connection to the vector database in the backend.

abstractmethod query(query_vector, top_k=10)[source]

Query the vector database in the backend.

property ready: bool

Check if the backend is ready for operations.

property vector_store: object

Get the vector store object for the backend.

class smarter.apps.vectorstore.backends.base.VectorStoreBackendConnection(*args, **kwargs)[source]

Bases: SmarterHelperMixin

Represents a connection to a vector store backend.

connect()[source]

Establish the connection to the vector store backend.

property ready: bool

Check if the connection is ready for operations.

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

Bases: SmarterException

Exception raised when there is an error with the vector store backend connection.

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

Bases: SmarterException

Exception raised when there is an error with the vector store backend.

smarter.apps.vectorstore.backends.base.should_log(level)[source]

Check if logging should be done based on the waffle switch.