WeaviateStore
features and configurations head to the API reference.
Overview
Integration details
Class | Package | PY support | Version |
---|---|---|---|
WeaviateStore | @langchain/weaviate | ✅ |
Setup
To use Weaviate vector stores, you’ll need to set up a Weaviate instance and install the@langchain/weaviate
integration package. You should also install the weaviate-client
package to initialize a client to connect to your instance with, and the uuid
package if you want to assign indexed documents ids.
This guide will also use OpenAI embeddings, which require you to install the @langchain/openai
integration package. You can also use other supported embeddings models if you wish.
Credentials
Once you’ve set up your instance, set the following environment variables:Instantiation
Connect a weaviate client
In most cases, you should use one of the connection helper functions to connect to your Weaviate instance:- connectToWeaviateCloud
- connectToLocal
- connectToCustom
Initiate the vectorStore
To create a collection, specify at least the collection name. If you don’t specify any properties,auto-schema
creates them.
schema
property when enabling the vector store. The collection name and other properties in schema
will take precedence when creating the vector store.
Manage vector store
Add items to vector store
Note: If you want to associate ids with your indexed documents, they must be UUIDs.Delete items from vector store
You can delete by id as by passing afilter
param:
Query vector store
Once your vector store has been created and the relevant documents have been added you will most likely wish to query it during the running of your chain or agent. In weaviate’s v3, the client interacts withcollections
as the primary way to work with objects in the database. The collection
object can be re-used throughout the codebase
Query directly
Performing a simple similarity search can be done as follows. TheFilter
helper class makes it easier to use filters with conditions. The v3 client streamlines how you use Filter
so your code is cleaner and more concise.
See this page for more on Weaviate filter syntax.
Hybrid Search
In Weaviate,Hybrid search
combines the results of a vector search and a keyword (BM25F) search by fusing the two result sets. To change the relative weights of the keyword and vector components, set the alpha
value in your query.
Check docs for the full list of hybrid search options.
Retrieval Augmented Generation (RAG)
Retrieval Augmented Generation (RAG) combines information retrieval with generative AI models. In Weaviate, a RAG query consists of two parts: a search query, and a prompt for the model. Weaviate first performs the search, then passes both the search results and your prompt to a generative AI model before returning the generated response.- @param query The query to search for.
- @param options available options for performing the hybrid search
- @param generate available options for the generation. Check docs for complete list
Query by turning into retriever
You can also transform the vector store into a retriever for easier usage in your chains.Usage for retrieval-augmented generation
For guides on how to use this vector store for retrieval-augmented generation (RAG), see the following sections:API reference
For detailed documentation of allWeaviateStore
features and configurations head to the API reference.