The ChromaHandshake class provides seamless integration between Chonkie’s chunking system and ChromaDB, a popular vector database.Embed and store your Chonkie chunks in ChromaDB without ever leaving the Chonkie SDK.
from chonkie import ChromaHandshake# Initialize with default settings (in-memory ChromaDB)handshake = ChromaHandshake()# Or specify a persistent storage pathhandshake = ChromaHandshake(path="./chroma_db")# Or use an existing Chroma clientimport chromadbclient = chromadb.Client()handshake = ChromaHandshake(client=client, collection_name="my_collection")
from chonkie import ChromaHandshake, SemanticChunkerhandshake = ChromaHandshake() # Initializes a new Chroma clientchunker = SemanticChunker()chunks = chunker("Chonkie is the best chonker ever!")handshake.write(chunks)
You can retrieve the most similar chunks from your ChromaDB collection using the search method:
Copy
Ask AI
from chonkie import ChromaHandshake# Initialize the handshakehandshake = ChromaHandshake(collection_name="my_documents")results = handshake.search(query="best chonker", limit=2)for result in results: print(result["score"], result["text"])