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.
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)
Similarity Search Results:LangChain is a framework for building intelligent apps.Semantic search enables advanced query matching.Upstash Vector is a scalable vector database.
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.