Export Chonkie’s Chunks into a Weaviate collection.
The WeaviateHandshake class provides seamless integration between Chonkie’s chunking system and Weaviate, a powerful vector database.Embed and store your Chonkie chunks in Weaviate without ever leaving the Chonkie SDK.
from chonkie import WeaviateHandshake# Initialize with default settings (local Weaviate)handshake = WeaviateHandshake()# Or connect to a Weaviate serverhandshake = WeaviateHandshake(url="http://localhost:8080", api_key= "YOUR_API_KEY")
from chonkie import WeaviateHandshake, SemanticChunker # Initialize the handshakehandshake = WeaviateHandshake( url="YOUR_CLOUD_URL", api_key="YOUR_API_KEY", collection_name="my_documents")# Create some chunkschunker = SemanticChunker()chunks = chunker.chunk("Chonkie loves to chonk your texts!")# Write chunks to Weaviatehandshake.write(chunks)
You can retrieve the most similar chunks from your Weaviate collection using the search method:
from chonkie import WeaviateHandshake# Initialize the handshakehandshake = WeaviateHandshake( url="YOUR_CLOUD_URL", api_key="YOUR_API_KEY", collection_name="my_documents")results = handshake.search(query="chonk your texts", limit=2)for result in results: print(result["score"], result["text"])
from chonkie import WeaviateHandshake# Initialize the handshakehandshake = WeaviateHandshake( url="YOUR_CLOUD_URL", api_key="YOUR_API_KEY", collection_name="my_documents")embedding = handshake.embedding_model.embed("chonk your texts").tolist()results = handshake.search(embedding=embedding, limit=2)for result in results: print(result["score"], result["text"])
from chonkie import WeaviateHandshake, SemanticChunker# Initialize the handshakehandshake = WeaviateHandshake( url="YOUR_CLOUD_URL", api_key="YOUR_API_KEY", collection_name="my_documents")# Create some chunkschunker = SemanticChunker(embedding_model=handshake.embedding_model)chunks = chunker.chunk("Chonkie loves to chonk your texts!")# Search the handshakeresults = handshake.search( embedding=chunks[0].sentences[0].embedding, limit=2,)for result in results: print(result["score"], result["text"])