Export Chonkie’s Chunks into a MongoDB collection.
The MongoDBHandshake class provides integration between Chonkie’s chunking system and MongoDB, a popular NoSQL database.Embed and store your Chonkie chunks in MongoDB directly from the Chonkie SDK.
from chonkie import MongoDBHandshake, SemanticChunker # Initialize the handshakehandshake = MongoDBHandshake( uri="mongodb://localhost:27017", db_name="my_documents", collection_name="my_collection")# Create some chunkschunker = SemanticChunker()chunks = chunker.chunk("Chonkie loves to chonk your texts!")# Write chunks to MongoDBhandshake.write(chunks)
You can retrieve the most similar chunks from your MongoDB collection using the search method:
Copy
Ask AI
from chonkie import MongoDBHandshake# Initialize the handshakehandshake = MongoDBHandshake( uri="mongodb://localhost:27017", db_name="my_documents", collection_name="my_collection")results = handshake.search(query="chonk your texts", limit=2)for result in results: print(result["score"], result["text"])