The LanceDBHandshake class provides seamless integration between Chonkie’s chunking system and LanceDB, a serverless vector database built on Apache Arrow.Embed and store your Chonkie chunks in LanceDB — locally or in the cloud — without ever leaving the Chonkie SDK.
from chonkie import LanceDBHandshake, SemanticChunker# Initialize the handshakehandshake = LanceDBHandshake(uri="./my_lancedb", table_name="my_documents")# Create some chunkschunker = SemanticChunker()chunks = chunker("Chonkie loves to chonk your texts!")# Write chunks to LanceDBhandshake.write(chunks)
You can retrieve the most similar chunks from your LanceDB table using the search method:
from chonkie import LanceDBHandshakehandshake = LanceDBHandshake(uri="./my_lancedb", table_name="my_documents")results = handshake.search(query="chonk your texts", limit=5)for result in results: print(result["score"], result["text"])
from chonkie import LanceDBHandshakehandshake = LanceDBHandshake(uri="./my_lancedb", table_name="my_documents")embedding = handshake.embedding_model.embed("chonk your texts").tolist()results = handshake.search(embedding=embedding, limit=5)for result in results: print(result["score"], result["text"])
URI of the LanceDB database. Use "memory://" for an ephemeral in-memory database, a local directory path for persistent storage, or a db:// URI for LanceDB Cloud.