Export Chonkie’s Chunks into an Elasticsearch index.
The ElasticHandshake class provides seamless integration between Chonkie’s chunking system and Elasticsearch, allowing you to leverage its powerful vector search capabilities.Embed and store your Chonkie chunks in an Elasticsearch index without ever leaving the Chonkie SDK. The handshake automatically handles index creation and the necessary vector field mapping.
from chonkie import ElasticHandshake, SentenceChunker# Initialize the handshake for your deploymenthandshake = ElasticHandshake( cloud_id="YOUR_CLOUD_ID", api_key="YOUR_API_KEY", index_name="my_documents",)# Create some chunkschunker = SentenceChunker()chunks = chunker.chunk("Chonkie uses the bulk API for efficient indexing. It's fast and reliable!")# Write chunks to Elasticsearchhandshake.write(chunks)
You can retrieve the most similar chunks from your Elasticsearch index using the search method, which performs a k-Nearest Neighbor (kNN) vector search.
from chonkie import ElasticHandshake# Initialize the handshake to connect to your indexhandshake = ElasticHandshake( hosts="YOUR_CLOUD_ID", api_key="YOUR_API_KEY", index_name="my_documents",)results = handshake.search(query="fast and efficient indexing", limit=2)
from chonkie import ElasticHandshake# Initialize the handshakehandshake = ElasticHandshake( hosts="YOUR_CLOUD_ID", api_key="YOUR_API_KEY", index_name="my_documents",)# Generate an embedding vector for your queryembedding = handshake.embedding_model.embed("fast and efficient indexing").tolist()results = handshake.search(embedding=embedding, limit=2)