VLite is a simple and blazing fast vector database that allows you to store and retrieve data semantically using embeddings. Made with numpy, vlite is a lightweight batteries-included database to implement RAG, similarity search, and embeddings into your projects.You’ll need to install langchain-community with pip install -qU langchain-community to use this integration
In this basic example, we load a text document, and store them in the VLite vector database. Then, we perform a similarity search to retrieve relevant documents based on a query.VLite handles chunking and embedding of the text for you, and you can change these parameters by pre-chunking the text and/or embeddings those chunks into the VLite database.
Copy
Ask AI
from langchain.document_loaders import TextLoaderfrom langchain.text_splitter import CharacterTextSplitter# Load the document and split it into chunksloader = TextLoader("path/to/document.txt")documents = loader.load()# Create a VLite instancevlite = VLite(collection="my_collection")# Add documents to the VLite vector databasevlite.add_documents(documents)# Perform a similarity searchquery = "What is the main topic of the document?"docs = vlite.similarity_search(query)# Print the most relevant documentprint(docs[0].page_content)
You can add texts or documents to the VLite vector database using the add_texts and add_documents methods, respectively.
Copy
Ask AI
# Add texts to the VLite vector databasetexts = ["This is the first text.", "This is the second text."]vlite.add_texts(texts)# Add documents to the VLite vector databasedocuments = [Document(page_content="This is a document.", metadata={"source": "example.txt"})]vlite.add_documents(documents)
VLite provides methods for performing similarity search on the stored documents.
Copy
Ask AI
# Perform a similarity searchquery = "What is the main topic of the document?"docs = vlite.similarity_search(query, k=3)# Perform a similarity search with scoresdocs_with_scores = vlite.similarity_search_with_score(query, k=3)
You can create VLite instances using various methods:
Copy
Ask AI
# Create a VLite instance from textsvlite = VLite.from_texts(texts)# Create a VLite instance from documentsvlite = VLite.from_documents(documents)# Create a VLite instance from an existing indexvlite = VLite.from_existing_index(collection="existing_collection")
VLite provides additional features for managing the vector database:
Copy
Ask AI
from langchain.vectorstores import VLitevlite = VLite(collection="my_collection")# Get the number of items in the collectioncount = vlite.count()# Save the collectionvlite.save()# Clear the collectionvlite.clear()# Get collection informationvlite.info()# Dump the collection datadata = vlite.dump()
Assistant
Responses are generated using AI and may contain mistakes.