LangChain OpenTutorial
  • πŸ¦œοΈπŸ”— The LangChain Open Tutorial for Everyone
  • 01-Basic
    • Getting Started on Windows
    • 02-Getting-Started-Mac
    • OpenAI API Key Generation and Testing Guide
    • LangSmith Tracking Setup
    • Using the OpenAI API (GPT-4o Multimodal)
    • Basic Example: Prompt+Model+OutputParser
    • LCEL Interface
    • Runnable
  • 02-Prompt
    • Prompt Template
    • Few-Shot Templates
    • LangChain Hub
    • Personal Prompts for LangChain
    • Prompt Caching
  • 03-OutputParser
    • PydanticOutputParser
    • PydanticOutputParser
    • CommaSeparatedListOutputParser
    • Structured Output Parser
    • JsonOutputParser
    • PandasDataFrameOutputParser
    • DatetimeOutputParser
    • EnumOutputParser
    • Output Fixing Parser
  • 04-Model
    • Using Various LLM Models
    • Chat Models
    • Caching
    • Caching VLLM
    • Model Serialization
    • Check Token Usage
    • Google Generative AI
    • Huggingface Endpoints
    • HuggingFace Local
    • HuggingFace Pipeline
    • ChatOllama
    • GPT4ALL
    • Video Q&A LLM (Gemini)
  • 05-Memory
    • ConversationBufferMemory
    • ConversationBufferWindowMemory
    • ConversationTokenBufferMemory
    • ConversationEntityMemory
    • ConversationKGMemory
    • ConversationSummaryMemory
    • VectorStoreRetrieverMemory
    • LCEL (Remembering Conversation History): Adding Memory
    • Memory Using SQLite
    • Conversation With History
  • 06-DocumentLoader
    • Document & Document Loader
    • PDF Loader
    • WebBaseLoader
    • CSV Loader
    • Excel File Loading in LangChain
    • Microsoft Word(doc, docx) With Langchain
    • Microsoft PowerPoint
    • TXT Loader
    • JSON
    • Arxiv Loader
    • UpstageDocumentParseLoader
    • LlamaParse
    • HWP (Hangeul) Loader
  • 07-TextSplitter
    • Character Text Splitter
    • 02. RecursiveCharacterTextSplitter
    • Text Splitting Methods in NLP
    • TokenTextSplitter
    • SemanticChunker
    • Split code with Langchain
    • MarkdownHeaderTextSplitter
    • HTMLHeaderTextSplitter
    • RecursiveJsonSplitter
  • 08-Embedding
    • OpenAI Embeddings
    • CacheBackedEmbeddings
    • HuggingFace Embeddings
    • Upstage
    • Ollama Embeddings With Langchain
    • LlamaCpp Embeddings With Langchain
    • GPT4ALL
    • Multimodal Embeddings With Langchain
  • 09-VectorStore
    • Vector Stores
    • Chroma
    • Faiss
    • Pinecone
    • Qdrant
    • Elasticsearch
    • MongoDB Atlas
    • PGVector
    • Neo4j
    • Weaviate
    • Faiss
    • {VectorStore Name}
  • 10-Retriever
    • VectorStore-backed Retriever
    • Contextual Compression Retriever
    • Ensemble Retriever
    • Long Context Reorder
    • Parent Document Retriever
    • MultiQueryRetriever
    • MultiVectorRetriever
    • Self-querying
    • TimeWeightedVectorStoreRetriever
    • TimeWeightedVectorStoreRetriever
    • Kiwi BM25 Retriever
    • Ensemble Retriever with Convex Combination (CC)
  • 11-Reranker
    • Cross Encoder Reranker
    • JinaReranker
    • FlashRank Reranker
  • 12-RAG
    • Understanding the basic structure of RAG
    • RAG Basic WebBaseLoader
    • Exploring RAG in LangChain
    • RAPTOR: Recursive Abstractive Processing for Tree-Organized Retrieval
    • Conversation-With-History
    • Translation
    • Multi Modal RAG
  • 13-LangChain-Expression-Language
    • RunnablePassthrough
    • Inspect Runnables
    • RunnableLambda
    • Routing
    • Runnable Parallel
    • Configure-Runtime-Chain-Components
    • Creating Runnable objects with chain decorator
    • RunnableWithMessageHistory
    • Generator
    • Binding
    • Fallbacks
    • RunnableRetry
    • WithListeners
    • How to stream runnables
  • 14-Chains
    • Summarization
    • SQL
    • Structured Output Chain
    • StructuredDataChat
  • 15-Agent
    • Tools
    • Bind Tools
    • Tool Calling Agent
    • Tool Calling Agent with More LLM Models
    • Iteration-human-in-the-loop
    • Agentic RAG
    • CSV/Excel Analysis Agent
    • Agent-with-Toolkits-File-Management
    • Make Report Using RAG, Web searching, Image generation Agent
    • TwoAgentDebateWithTools
    • React Agent
  • 16-Evaluations
    • Generate synthetic test dataset (with RAGAS)
    • Evaluation using RAGAS
    • HF-Upload
    • LangSmith-Dataset
    • LLM-as-Judge
    • Embedding-based Evaluator(embedding_distance)
    • LangSmith Custom LLM Evaluation
    • Heuristic Evaluation
    • Compare experiment evaluations
    • Summary Evaluators
    • Groundedness Evaluation
    • Pairwise Evaluation
    • LangSmith Repeat Evaluation
    • LangSmith Online Evaluation
    • LangFuse Online Evaluation
  • 17-LangGraph
    • 01-Core-Features
      • Understanding Common Python Syntax Used in LangGraph
      • Title
      • Building a Basic Chatbot with LangGraph
      • Building an Agent with LangGraph
      • Agent with Memory
      • LangGraph Streaming Outputs
      • Human-in-the-loop
      • LangGraph Manual State Update
      • Asking Humans for Help: Customizing State in LangGraph
      • DeleteMessages
      • DeleteMessages
      • LangGraph ToolNode
      • LangGraph ToolNode
      • Branch Creation for Parallel Node Execution
      • Conversation Summaries with LangGraph
      • Conversation Summaries with LangGraph
      • LangGrpah Subgraph
      • How to transform the input and output of a subgraph
      • LangGraph Streaming Mode
      • Errors
      • A Long-Term Memory Agent
    • 02-Structures
      • LangGraph-Building-Graphs
      • Naive RAG
      • Add Groundedness Check
      • Adding a Web Search Module
      • LangGraph-Add-Query-Rewrite
      • Agentic RAG
      • Adaptive RAG
      • Multi-Agent Structures (1)
      • Multi Agent Structures (2)
    • 03-Use-Cases
      • LangGraph Agent Simulation
      • Meta Prompt Generator based on User Requirements
      • CRAG: Corrective RAG
      • Plan-and-Execute
      • Multi Agent Collaboration Network
      • Multi Agent Collaboration Network
      • Multi-Agent Supervisor
      • 08-LangGraph-Hierarchical-Multi-Agent-Teams
      • 08-LangGraph-Hierarchical-Multi-Agent-Teams
      • SQL-Agent
      • 10-LangGraph-Research-Assistant
      • LangGraph Code Assistant
      • Deploy on LangGraph Cloud
      • Tree of Thoughts (ToT)
      • Ollama Deep Researcher (Deepseek-R1)
      • Functional API
      • Reflection in LangGraph
  • 19-Cookbook
    • 01-SQL
      • TextToSQL
      • SpeechToSQL
    • 02-RecommendationSystem
      • ResumeRecommendationReview
    • 03-GraphDB
      • Movie QA System with Graph Database
      • 05-TitanicQASystem
      • Real-Time GraphRAG QA
    • 04-GraphRAG
      • Academic Search System
      • Academic QA System with GraphRAG
    • 05-AIMemoryManagementSystem
      • ConversationMemoryManagementSystem
    • 06-Multimodal
      • Multimodal RAG
      • Shopping QnA
    • 07-Agent
      • 14-MoARAG
      • CoT Based Smart Web Search
      • 16-MultiAgentShoppingMallSystem
      • Agent-Based Dynamic Slot Filling
      • Code Debugging System
      • New Employee Onboarding Chatbot
      • 20-LangGraphStudio-MultiAgent
      • Multi-Agent Scheduler System
    • 08-Serving
      • FastAPI Serving
      • Sending Requests to Remote Graph Server
      • Building a Agent API with LangServe: Integrating Currency Exchange and Trip Planning
    • 08-SyntheticDataset
      • Synthetic Dataset Generation using RAG
    • 09-Monitoring
      • Langfuse Selfhosting
Powered by GitBook
On this page
  • Overview
  • Key Sections:
  • Table of Contents
  • References
  • Conceptual Guide of Vector Store
  • Why Vector Store Is Essential
  • Interface
  • Understanding Search Methods
  • How Similarity Search Works
  • Types of Searches in Vector Stores
  • Vector Store as a Retriever
  • Integration
  1. 09-VectorStore

Vector Stores

Previous09-VectorStoreNextChroma

Last updated 28 days ago

  • Author:

  • Peer Review:

  • This is a part of

Overview

This tutorial provides a comprehensive guide to vector stores, which are specialized databases for indexing and retrieving information using vector representations (embeddings). It highlights their importance in enabling fast, scalable, and semantic search across unstructured data like text, images, and audio.

Key Sections:

  1. Essentials of Vector Stores :

    • Focus on the need for semantic search, scalability, and efficient retrieval.

    • Overview of how vector stores outperform traditional keyword-based search systems.

  2. LangChain Interface :

    • Explanation of core methods such as add_documents , upsert_documents , delete_documents , and similarity_search .

    • Introduction to advanced features like parallel document processing.

  3. Search Methods :

    • Covers Keyword-Based Search , which relies on exact term matching, and Similarity-Based Search , which identifies semantically related results using embeddings.

    • Explains Score-Based Similarity Search , which ranks documents based on relevance using metrics such as cosine similarity .

    • Discusses advanced search techniques, including Sparse , Dense , and Hybrid Search , to improve retrieval performance.

    • Demonstrates the use of LangChain’s .as_retriever() method for seamless integration with retrieval pipelines.

  4. Integration of Popular Vector Stores :

    • Overview of prominent vector stores such as Chroma, FAISS, Pinecone, Qdrant, Elasticsearch, MongoDB, pgvector, Neo4j, Weaviate, and Milvus.

    • Each store’s strengths and suitable use cases are briefly summarized.

This tutorial serves as a foundational guide to understanding and leveraging vector stores for AI-driven applications. It bridges basic concepts with advanced implementations, offering insights into efficient data retrieval and integration strategies within LangChain’s ecosystem.

Table of Contents

References


Conceptual Guide of Vector Store

Prerequisite: 07-TextSplitter 08-Embedding

Vector stores are specialized databases designed to index and retrieve information using vector representations (embeddings).

They are commonly utilized to search through unstructured data, such as text, images, and audio, by identifying semantically similar content rather than relying on exact keyword matches.

Why Vector Store Is Essential

  1. Fast and Efficient Search

By properly storing and indexing embedding vectors, vector stores allow for the rapid retrieval of relevant information, even when dealing with massive datasets.

  1. Scalability for Growing Data

As data continues to expand, vector stores must scale efficiently. A well-structured vector store ensures the system can handle large-scale data without performance issues, supporting seamless growth.

  1. Facilitating Semantic Search

Unlike traditional keyword-based search, semantic search retrieves content based on meaning. Vector stores enable this by finding paragraphs or sections that closely align with a user’s query in context. This is a key advantage over databases that store raw text, which are limited to exact keyword matches.

Interface

LangChain provides a unified interface for interacting with vector stores, allowing users to seamlessly switch between various implementations.

This interface includes core methods for writing, deleting, and searching documents within the vector store.

The main methods are as follows:

  • add_documents : Adds a list of texts to the vector store.

  • upsert_documents : Adds new documents to the vector store or updates existing ones if they already exist.

    • In this tutorial, we'll also introduce the upsert_documents_parallel method, which enables efficient bulk processing of data when applicable.

  • delete_documents : Deletes a list of documents from the vector store.

  • similarity_search : Searches for documents similar to a given query.

Understanding Search Methods

  • Keyword-Based Search This method relies on matching exact words or phrases in the query with those in the document. It’s simple but lacks the ability to capture semantic relationships between terms.

  • Similarity-Based Search Uses vector representations to evaluate how semantically similar the query is to the documents. It provides more accurate results, especially for natural language queries.

  • Score-Based Similarity Search Assigns a similarity score to each document based on the query. Higher scores indicate stronger relevance. Commonly uses metrics like cosine similarity or distance-based scoring.

How Similarity Search Works

  • Concept of Embeddings and Vectors Embeddings are numerical representations of words or documents in a high-dimensional space. They capture semantic meaning, enabling better comparison between query and documents.

  • Similarity Measurement Methods

    • Cosine Similarity: Measures the cosine of the angle between two vectors. Values closer to 1 indicate higher similarity.

    • Euclidean Distance: Calculates the straight-line distance between two points in vector space. Smaller distances imply higher similarity.

  • Scoring and Ranking Search Results After calculating similarity, documents are assigned scores. Results are ranked in descending order of relevance based on these scores.

  • Brief Overview of Search Algorithms

    • TF-IDF: Weights terms based on their frequency in a document relative to their occurrence across all documents.

    • BM25: A refined version of TF-IDF, optimized for relevance in information retrieval.

    • Neural Search: Leverages deep learning to generate context-aware embeddings for more accurate results.

Types of Searches in Vector Stores

  • Similarity Search : Finds documents with embeddings most similar to the query. Ideal for semantic search applications.

  • Maximal Marginal Relevance (MMR) Search : Balances relevance and diversity in search results by prioritizing diverse yet relevant documents.

  • Sparse Retriever : Uses traditional keyword-based methods like TF-IDF or BM25 to retrieve documents. Effective for datasets with limited context.

  • Dense Retriever : Relies on dense vector embeddings to capture semantic meaning. Common in modern search systems using deep learning.

  • Hybrid Search : Combines sparse and dense retrieval methods. Balances the precision of dense methods with the broad coverage of sparse methods for optimal results.

Vector Store as a Retriever

  • Functionality : By converting a vector store into a retriever using the .as_retriever() method, you create a lightweight wrapper that conforms to LangChain’s retriever interface. This enables the use of various retrieval strategies, such as similarity search and maximal marginal relevance (MMR) search, and allows for customization of retrieval parameters. οΏΌ

  • Use Case : Ideal for complex applications where the retriever needs to be part of a larger pipeline, such as retrieval-augmented generation (RAG) systems. It facilitates seamless integration with other components in LangChain, enabling functionalities like ensemble retrieval methods and advanced query analysis. οΏΌ

In summary, while direct vector store searches provide basic retrieval capabilities, converting a vector store into a retriever offers enhanced flexibility and integration within LangChain’s ecosystem, supporting more sophisticated retrieval strategies and applications.

Integration

Here is a brief overview of the vector stores covered in this tutorial:

  • Chroma : An open-source vector database designed for AI applications, enabling efficient storage and retrieval of embeddings.

  • FAISS : Developed by Facebook AI, FAISS (Facebook AI Similarity Search) is a library for efficient similarity search and clustering of dense vectors. οΏΌ

  • Pinecone : A managed vector database service that provides high-performance vector similarity search, enabling developers to build scalable AI applications.

  • Qdrant : Qdrant (read: quadrant ) is a vector similarity search engine. It provides a production-ready service with a convenient API to store, search, and manage vectors with additional payload and extended filtering support. It makes it useful for all sorts of neural network or semantic-based matching, faceted search, and other applications.

  • Elasticsearch : A distributed, RESTful search and analytics engine that supports vector search, allowing for efficient similarity searches within large datasets.

  • MongoDB : MongoDB Atlas Vector Search enables efficient storage, indexing, and querying of vector embeddings alongside your operational data, facilitating seamless implementation of AI-driven applications.

  • pgvector (PostgreSQL) : An extension for PostgreSQL that adds vector similarity search capabilities, allowing for efficient storage and querying of vector data within a relational database.

  • Neo4j : A graph database that stores nodes and relationships, with native support for vector search, facilitating complex queries involving both graph and vector data. οΏΌ

  • Weaviate : An open-source vector database that allows for storing data objects and vector embeddings, supporting various data types and offering semantic search capabilities.

  • Milvus : A database that stores, indexes, and manages massive embedding vectors generated by machine learning models, designed for high-performance vector similarity search. οΏΌ

These vector stores are integral in building applications that require efficient similarity search and management of high-dimensional data.

Vector Store
Delete by ID
Filtering
Search by Vector
Search with Score
Async
Passes Standard Tests
Multi Tenancy
IDs in Add Documents

Chroma

βœ…

βœ…

βœ…

βœ…

βœ…

❌

❌

❌

Faiss

βœ…

βœ…

βœ…

βœ…

βœ…

❌

❌

❌

Pinecone

βœ…

βœ…

βœ…

❌

βœ…

❌

❌

❌

Qdrant

βœ…

βœ…

βœ…

βœ…

βœ…

❌

❌

❌

Elasticsearch

βœ…

βœ…

βœ…

βœ…

βœ…

❌

❌

❌

MongoDB-Atlas (MongoDB)

βœ…

βœ…

βœ…

βœ…

βœ…

❌

❌

❌

PGVector (PostgreSQL)

βœ…

βœ…

βœ…

βœ…

βœ…

❌

❌

❌

Neo4j

βœ…

βœ…

βœ…

βœ…

βœ…

❌

❌

βœ…

Weaviate

βœ…

βœ…

βœ…

βœ…

βœ…

❌

βœ…

❌

Milvus

βœ…

βœ…

❌

βœ…

βœ…

❌

❌

❌

LangChain How-to guides: Vector store
Concept of Vector stores from LangChain
Vector store supported integrations of LangChain
Top 10 Vector Stores
Vector Databases: Comparison for Semantic Search and Retrieval-Augmented Generation
Overview
Conceptual Guide of Vectore Store
Integration
Youngin Kim
ro__o_jun
LangChain Open Tutorial