VLite는 embedding을 사용하여 의미론적으로 데이터를 저장하고 검색할 수 있는 간단하고 매우 빠른 vector database입니다. numpy로 만들어진 vlite는 RAG, 유사도 검색, embedding을 프로젝트에 구현하기 위한 경량 배터리 포함 database입니다. 이 integration을 사용하려면 pip install -qU langchain-communitylangchain-community를 설치해야 합니다

설치

LangChain에서 VLite를 사용하려면 vlite package를 설치해야 합니다:
!pip install vlite

VLite Import하기

from langchain_community.vectorstores import VLite

기본 예제

이 기본 예제에서는 텍스트 문서를 로드하고 VLite vector database에 저장합니다. 그런 다음 쿼리를 기반으로 관련 문서를 검색하기 위해 유사도 검색을 수행합니다. VLite는 텍스트의 chunking과 embedding을 자동으로 처리하며, 텍스트를 미리 chunking하거나 해당 chunk를 VLite database에 embedding하여 이러한 매개변수를 변경할 수 있습니다.
from langchain.document_loaders import TextLoader
from langchain.text_splitter import CharacterTextSplitter

# Load the document and split it into chunks
loader = TextLoader("path/to/document.txt")
documents = loader.load()

# Create a VLite instance
vlite = VLite(collection="my_collection")

# Add documents to the VLite vector database
vlite.add_documents(documents)

# Perform a similarity search
query = "What is the main topic of the document?"
docs = vlite.similarity_search(query)

# Print the most relevant document
print(docs[0].page_content)

Text와 Document 추가하기

add_textsadd_documents method를 사용하여 VLite vector database에 text 또는 document를 추가할 수 있습니다.
# Add texts to the VLite vector database
texts = ["This is the first text.", "This is the second text."]
vlite.add_texts(texts)

# Add documents to the VLite vector database
documents = [Document(page_content="This is a document.", metadata={"source": "example.txt"})]
vlite.add_documents(documents)

유사도 검색

VLite는 저장된 document에 대한 유사도 검색을 수행하는 method를 제공합니다.
# Perform a similarity search
query = "What is the main topic of the document?"
docs = vlite.similarity_search(query, k=3)

# Perform a similarity search with scores
docs_with_scores = vlite.similarity_search_with_score(query, k=3)

Max Marginal Relevance 검색

VLite는 Max Marginal Relevance (MMR) 검색도 지원하며, 이는 쿼리와의 유사성과 검색된 document 간의 다양성을 모두 최적화합니다.
# Perform an MMR search
docs = vlite.max_marginal_relevance_search(query, k=3)

Document 업데이트 및 삭제

update_documentdelete method를 사용하여 VLite vector database의 document를 업데이트하거나 삭제할 수 있습니다.
# Update a document
document_id = "doc_id_1"
updated_document = Document(page_content="Updated content", metadata={"source": "updated.txt"})
vlite.update_document(document_id, updated_document)

# Delete documents
document_ids = ["doc_id_1", "doc_id_2"]
vlite.delete(document_ids)

Document 검색하기

get method를 사용하여 ID 또는 metadata를 기반으로 VLite vector database에서 document를 검색할 수 있습니다.
# Retrieve documents by IDs
document_ids = ["doc_id_1", "doc_id_2"]
docs = vlite.get(ids=document_ids)

# Retrieve documents by metadata
metadata_filter = {"source": "example.txt"}
docs = vlite.get(where=metadata_filter)

VLite Instance 생성하기

다양한 method를 사용하여 VLite instance를 생성할 수 있습니다:
# Create a VLite instance from texts
vlite = VLite.from_texts(texts)

# Create a VLite instance from documents
vlite = VLite.from_documents(documents)

# Create a VLite instance from an existing index
vlite = VLite.from_existing_index(collection="existing_collection")

추가 기능

VLite는 vector database 관리를 위한 추가 기능을 제공합니다:
from langchain.vectorstores import VLite
vlite = VLite(collection="my_collection")

# Get the number of items in the collection
count = vlite.count()

# Save the collection
vlite.save()

# Clear the collection
vlite.clear()

# Get collection information
vlite.info()

# Dump the collection data
data = vlite.dump()

Connect these docs programmatically to Claude, VSCode, and more via MCP for real-time answers.
I