Skip to main content
The PineconeHandshake class provides seamless integration between Chonkie’s chunking system and Pinecone, a managed vector database. Embed and store your Chonkie chunks in Pinecone directly from the Chonkie SDK.

Installation

Before using the Pinecone handshake, make sure to install the required dependencies:
pip install chonkie[pinecone]

Initialization

from chonkie import PineconeHandshake
handshake = PineconeHandshake(api_key="YOUR_API_KEY")

Parameters

client
Optional[pinecone.Pinecone]
default:"None"
Pinecone client instance. If not provided, a new client will be created based on other parameters.
api_key
Optional[str]
default:"None"
Pinecone API key for authentication.
index_name
Union[str, Literal['random']]
default:"random"
Name of the index to use. If “random”, a unique name will be generated.
embedding_model
Union[str, BaseEmbeddings]
default:"minishlab/potion-retrieval-32M"
Embedding model to use. Can be a model name or a BaseEmbeddings instance.
dimension
Optional[int]
default:"None"
Dimension of the embeddings. If not provided, will be inferred from the embedding model.
**kwargs
Dict[str, Any]
default:"{}"
Additional keyword arguments to pass to the Pinecone client or index creation.

Writing Chunks to Pinecone

from chonkie import PineconeHandshake, SemanticChunker    

# Initialize the handshake
handshake = PineconeHandshake(api_key="YOUR_API_KEY", index_name="my_documents")

# Create some chunks
chunker = SemanticChunker()
chunks = chunker.chunk("Chonkie loves to chonk your texts!")

# Write chunks to Pinecone
handshake.write(chunks)

Searching Chunks in Pinecone

You can retrieve the most similar chunks from your Pinecone index using the search method:
from chonkie import PineconeHandshake

# Initialize the handshake
handshake = PineconeHandshake(api_key="YOUR_API_KEY", index_name="my_documents")
results = handshake.search(query="chonk your texts", limit=2)
for result in results:
    print(result["score"], result["text"])
I