Vectorstore Pinecone Backend
The Pinecone backend: a managed service.
See https://www.pinecone.io/. A vectorstore is one serverless Pinecone index. Its API key is
the Secret of the vectorstore’s ApiConnection. The backend embeds the chunks itself, here, in the app, and sends each
operation, one of smarter.apps.vectorstore.execution’s, through the tool runner, which calls Pinecone from the
tool worker (ADR-038). The chunks’ text is in the metadata’s text, where LangChain’s
PineconeVectorStore stores it, so indexes that it wrote stay searchable. Dumps are Pinecone backups, which Pinecone keeps,
and which require a paid Pinecone plan.
- class smarter.apps.vectorstore.backends.pinecone.PineconeBackend(vectorstore, embeddings=None, client=None)[source]
Bases:
SmarterVectorstoreBackendThe Pinecone backend.
- Parameters:
client (
Any) – A Pinecone client, e.g. a mock in tests, which the operations run on in this process. By default there is none, and each operation goes through the tool runner, with the API key of the vectorstore’s ApiConnection.
- api_key()[source]
The API key of the vectorstore’s ApiConnection, read here, in the app.
- Raises:
VectorStoreBackendCredentialsError – If the vectorstore has no ApiConnection with an API key.
- Return type:
- check_credentials()[source]
Check that Pinecone accepts the api key, by asking whether the index exists.
- Return type:
- Returns:
What was found, for a person.
- Raises:
VectorStoreBackendCredentialsError – If Pinecone refuses the api key.
VectorStoreBackendConnectionError – If Pinecone can’t be reached.
- create()[source]
Create a serverless Pinecone index, in the cloud and region of the spec’s
pinecone.It is tagged with the platform’s name and the vectorstore’s id, and has deletion protection if the vectorstore has. It returns at once: Pinecone initializes the index for a minute or two, which
index_ready()reports, rather than holding a request or a worker while it does.- Raises:
VectorStoreBackendError – If Pinecone did not create it, as
pinecone_error()classifies it.- Return type:
- create_snapshot(name)[source]
Back up the index, with Pinecone’s backups.
- Parameters:
name (
str) – The backup’s name.- Return type:
SnapshotInfo- Returns:
The backup’s id, size, and whether it is ready.
- Raises:
VectorStoreBackendError – If Pinecone did not back it up.
- deletion_protection()[source]
Pinecone’s deletion protection of the index:
enabledif the vectorstore has it.- Return type:
- drop()[source]
Delete the Pinecone index, if it exists, and its data.
It returns at once, while Pinecone deletes the index.
- Return type:
- exists()[source]
Whether the Pinecone index exists.
- Raises:
VectorStoreBackendCredentialsError – If Pinecone refuses the api key.
VectorStoreBackendConnectionError – If Pinecone is unreachable.
- Return type:
- index_ready()[source]
Whether the index, which exists, is ready.
Pinecone takes a minute or two to initialize a new one.
- operation(name, params=None, timeout=30.0)[source]
Run one of the index’s operations: through the tool runner, or in process on an injected client.
- restore_snapshot(name)[source]
Replace the index with a new one from the backup.
Pinecone requires that the index is deleted first, so this waits until it is.
- Return type:
- search(query, k=4, search_type='similarity', score_threshold=None, fetch_k=None, lambda_mult=None, metadata_filter=None)[source]
Search the index with the query’s embedding, computed here.
Scores are Pinecone’s raw scores for the index’s metric. MMR re-ranks
fetch_kmatches for diversity, and its results have no score.- Parameters:
query (
str) – The text to search for.k (
int) – How many results to return.search_type (
str) –similarity,similarity_score_thresholdormmr.score_threshold (
float|None) – Forsimilarity_score_threshold, the lowest score to keep. A result without a score is dropped.fetch_k (
int|None) – Formmr, how many matches to re-rank. Defaults tomax(20, k * 4).lambda_mult (
float|None) – Formmr, from 0 (most diverse) to 1 (most relevant). Defaults to 0.5.metadata_filter (
dict[str,Any] |None) – A Pinecone metadata filter.
- Return type:
list[SearchResult]- Returns:
The matching chunks, best first.
- smarter.apps.vectorstore.backends.pinecone.pinecone_error(operation, error)[source]
Return the backend error of an exception from Pinecone, by whether retrying could help.
- Parameters:
- Return type:
VectorStoreBackendError- Returns:
A credentials error for a refused api key, a rejected error for another request that Pinecone would refuse again, and a connection error for anything else, e.g. a timeout or a 5xx, which may pass.