Using Weaviate Vector Store in LangChain
Posted: Nov 21, 2024.
The Weaviate vector store integration in LangChain provides a powerful way to store and search vector embeddings. This guide will walk you through using the Weaviate vector store class and its key features.
What is Weaviate Vector Store?
Weaviate is an open-source vector database that allows you to store data objects alongside their vector embeddings. The LangChain Weaviate integration provides a wrapper around the Weaviate client that makes it easy to:
- Store documents and their embeddings
- Perform semantic similarity searches
- Filter and retrieve documents based on metadata
- Manage documents with CRUD operations
Reference
Here are the key methods provided by the Weaviate vector store class:
Method | Description |
---|---|
from_texts | Create a Weaviate instance from a list of texts and embeddings |
from_documents | Create a Weaviate instance from a list of Documents |
add_texts | Add new texts and their embeddings to the store |
add_documents | Add new documents to the store |
similarity_search | Find similar documents using semantic search |
similarity_search_with_score | Get similar documents with relevance scores |
max_marginal_relevance_search | Use MMR to get diverse similar documents |
delete | Remove documents by ID |
How to Use Weaviate Vector Store
Basic Setup and Initialization
First, you'll need to install and initialize the Weaviate client:
Adding Documents
You can add documents in two ways:
Performing Searches
Weaviate supports different types of searches:
Using Filters and Metadata
You can filter search results using metadata:
Document Management
Using as a Retriever
The Weaviate vector store can be used directly as a retriever in LangChain chains:
This guide covers the main functionality of the Weaviate vector store in LangChain. The integration provides a robust foundation for building semantic search and retrieval systems with additional features like asynchronous operations (prefixed with 'a') for all main methods.
An alternative to LangSmith
Open-source LangChain monitoring, prompt management, and magic. Get started in 2 minutes.
LangChain DocsJoin 10,000+ subscribers
Every 2 weeks, latest model releases and industry news.
An alternative to LangSmith
Open-source LangChain monitoring, prompt management, and magic. Get started in 2 minutes.