## vlite

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.

## Installation[​](#installation "Direct link to Installation")

To use the VLite in LangChain, you need to install the `vlite` package:

## Importing VLite[​](#importing-vlite "Direct link to Importing VLite")

```
from langchain.vectorstores import VLite
```

## Basic Example[​](#basic-example "Direct link to Basic Example")

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.

```
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)
```

## Adding Texts and Documents[​](#adding-texts-and-documents "Direct link to Adding Texts and Documents")

You can add texts or documents to the VLite vector database using the `add_texts` and `add_documents` methods, respectively.

```
# 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)
```

## Similarity Search[​](#similarity-search "Direct link to Similarity Search")

VLite provides methods for performing similarity search on the stored documents.

```
# 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)
```

## Max Marginal Relevance Search[​](#max-marginal-relevance-search "Direct link to Max Marginal Relevance Search")

VLite also supports Max Marginal Relevance (MMR) search, which optimizes for both similarity to the query and diversity among the retrieved documents.

```
# Perform an MMR searchdocs = vlite.max_marginal_relevance_search(query, k=3)
```

## Updating and Deleting Documents[​](#updating-and-deleting-documents "Direct link to Updating and Deleting Documents")

You can update or delete documents in the VLite vector database using the `update_document` and `delete` methods.

```
# Update a documentdocument_id = "doc_id_1"updated_document = Document(page_content="Updated content", metadata={"source": "updated.txt"})vlite.update_document(document_id, updated_document)# Delete documentsdocument_ids = ["doc_id_1", "doc_id_2"]vlite.delete(document_ids)
```

## Retrieving Documents[​](#retrieving-documents "Direct link to Retrieving Documents")

You can retrieve documents from the VLite vector database based on their IDs or metadata using the `get` method.

```
# Retrieve documents by IDsdocument_ids = ["doc_id_1", "doc_id_2"]docs = vlite.get(ids=document_ids)# Retrieve documents by metadatametadata_filter = {"source": "example.txt"}docs = vlite.get(where=metadata_filter)
```

## Creating VLite Instances[​](#creating-vlite-instances "Direct link to Creating VLite Instances")

You can create VLite instances using various methods:

```
# 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")
```

## Additional Features[​](#additional-features "Direct link to Additional Features")

VLite provides additional features for managing the vector database:

```
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()
```