Vectorstore Pinecone Backend

Backend implementation for the Pinecode vectorstore. see: https://www.pinecone.io/

class smarter.apps.vectorstore.backends.pinecone.PineconeBackend(db)[source]

Bases: SmarterVectorstoreBackend

Backend implementation for the Pinecone vectorstore.

__init__(db)[source]

Initialize the PineconeBackend instance.

Sets up the Pinecone backend using the provided VectorestoreMeta configuration. Validates the backend type, provider, and API keys, then initializes the backend state and index name.

Parameters:

db (VectorestoreMeta) – The VectorestoreMeta configuration object.

Raises:

VectorStoreBackendError – If the backend type, provider, or API keys are invalid.

add_documents(documents, embeddings)[source]

Add documents with their corresponding embeddings to the vector store.

Adds a list of documents and their precomputed embeddings to the Pinecone vector store. It emits signals to indicate the start, success, or failure of the loading process.

Parameters:
  • documents (list[Document]) – List of LangChain Document objects to be added to the vector store.

  • embeddings (list[Any]) – List of embedding vectors corresponding to the documents.

Returns:

True if documents were added successfully.

Return type:

bool

Raises:

VectorStoreBackendError – If there is an error adding documents to the vector store.

connect()[source]

Connect to the Pinecone service.

Initializes the Pinecone client using the configured API key. If the connection is successful, the client instance is stored for future use.

Returns:

True if the connection was successful.

Return type:

bool

Raises:

VectorStoreBackendConnectionError – If there is an error initializing the Pinecone client.

create()[source]

Create a new Pinecone index.

Creates a new Pinecone index with the current configuration. If the index already exists, this will raise an error.

Returns:

None

Return type:

None

Raises:
  • VectorStoreBackendConnectionError – If the Pinecone client is not initialized.

  • VectorStoreBackendError – If the index name is not set or if there is an error creating the index.

delete()[source]

Delete the Pinecone index.

Deletes the Pinecone index if it exists. If the index does not exist, the method returns without error.

Returns:

None

Return type:

None

Raises:
  • VectorStoreBackendConnectionError – If the Pinecone client is not initialized.

  • VectorStoreBackendError – If the index name is not set.

disconnect()[source]

Disconnect from the Pinecone index.

Resets the Pinecone client instance, effectively disconnecting from the Pinecone service.

Returns:

None

Return type:

None

property index: Index | None

Get the Pinecone index instance.

Lazily initializes and returns the Pinecone Index instance for the current index name. If the index is already initialized, returns the existing instance.

Returns:

The Pinecone Index instance if initialized, otherwise None.

Return type:

Optional[Index]

Raises:

VectorStoreBackendConnectionError – If the Pinecone client or index name is not set, or if there is an error initializing the index.

property index_name: str | None

index name.

property index_stats: str

Get the statistics of the Pinecone index.

Retrieves and returns the statistics of the current Pinecone index as a formatted JSON string. If the index is not initialized, returns a message indicating so.

Returns:

A JSON string with index statistics, or a message if the index is not initialized.

Return type:

str

init()[source]

Initialize Pinecone backend attributes.

Resets all internal attributes related to the Pinecone backend, including index, index name, text splitter, embeddings, and vector store. This is typically called before re-initializing or switching the backend state.

Returns:

None

Return type:

None

init_index()[source]

Verify and create Pinecone index if needed.

Checks if an index with the name stored in self.index_name exists in Pinecone. If it does not exist, creates a new index with the current configuration.

Returns:

None

Return type:

None

Raises:

VectorStoreBackendConnectionError – If the Pinecone client is not initialized or the index name is not set.

initialize()[source]

Initialize the Pinecone index.

Deletes the existing index (if it exists) and creates a new one with the current configuration. This operation is typically used to reset the vector store to a clean state.

Returns:

None

Return type:

None

Raises:

VectorStoreBackendError – If there is an error deleting or creating the index.

property initialized: bool

Check if the Pinecone index is initialized.

Verifies that the Pinecone client is initialized and that the index name exists in Pinecone.

Returns:

True if the index exists and the client is initialized, otherwise False.

Return type:

bool

property pinecone: Pinecone | None

Get the Pinecone instance.

Lazily initializes and returns the Pinecone client instance using the configured API key. If the client is already initialized, returns the existing instance.

Returns:

The Pinecone client instance if initialized, otherwise None.

Return type:

Optional[Pinecone]

Raises:

VectorStoreBackendConnectionError – If there is an error initializing the Pinecone client.

pinecone_api_key: SecretStr
query(query_vector, top_k=10)[source]

Query the vector database in the backend.

property ready: bool

Check if the Pinecone backend is fully ready.

Returns True if the backend is fully initialized, the Pinecone index exists, and the vector store is available.

Returns:

True if the backend is ready for use, otherwise False.

Return type:

bool

property vector_store: PineconeVectorStore

Get the Pinecone vector store.

Lazily initializes and returns the PineconeVectorStore instance using the current index and embeddings. If the vector store is already initialized, returns the existing instance.

Returns:

The PineconeVectorStore instance.

Return type:

PineconeVectorStore

Raises:

VectorStoreBackendConnectionError – If the vector store cannot be initialized due to missing index or embeddings.

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

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