Integrations
LangChain with Upstash Vector
You can use LangChain with Upstash Vector to perform semantic search and manage vector embeddings. LangChain is a powerful framework that integrates with vector databases, including Upstash Vector, making it easy to build intelligent applications.
First, we need to create a Vector Index in the Upstash Console. To learn more about index creation, you can check out this page.
Install
pip install upstash-vector langchain langchain-community python-dotenvUsage
from dotenv import load_dotenvfrom langchain_community.vectorstores.upstash import UpstashVectorStorefrom langchain.schema import Document# Load environment variablesload_dotenv()# Create a vector store instancestore = UpstashVectorStore( embedding=True, # Embedding option enabled)# Sample documents to uploaddocuments = [ Document(page_content="Upstash Vector is a scalable vector database."), Document(page_content="LangChain is a framework for building intelligent apps."), Document(page_content="Semantic search enables advanced query matching."),]# Add documents to the Upstash Vector indexstore.add_documents(documents)# Perform a similarity searchquery = "What is LangChain?"results = store.similarity_search(query, k=3)print("Similarity Search Results:")for res in results: print(res.page_content)Query Results
Similarity Search Results:LangChain is a framework for building intelligent apps.Semantic search enables advanced query matching.Upstash Vector is a scalable vector database.Features
Semantic Search: Retrieve the most contextually relevant results using embeddings and vector similarity.
Namespace Support: Separate documents into different namespaces for better organization.
Metada Filtering: Metadata can be used to filter the results of a query.
Notes
- Upstash Vector supports custom embeddings; you can specify an embedding model when initializing
UpstashVectorStore. - Use
.envfiles to manage your Upstash credentials for secure and reusable configuration.
To learn more, visit the LangChain documentation.