!function(){function t(t){document.documentElement.setAttribute("data-theme",t)}var e=function(){var t=null;try{t=new URLSearchParams(window.location.search).get("docusaurus-theme")}catch(t){}return t}()||function(){var t=null;try{t=localStorage.getItem("theme")}catch(t){}return t}();t(null!==e?e:"light")}(),document.documentElement.setAttribute("data-announcement-bar-initially-dismissed",function(){try{return"true"===localStorage.getItem("docusaurus.announcement.dismiss")}catch(t){}return!1}())

[Skip to main content](#__docusaurus_skipToContent_fallback)

LangChain v0.2 is coming soon! Preview the new docs [here](/v0.2/docs/introduction/).

[

![🦜️🔗 Langchain](/v0.1/img/brand/wordmark.png)![🦜️🔗 Langchain](/v0.1/img/brand/wordmark-dark.png)

](/v0.1/)[Docs](/v0.1/docs/get_started/introduction/)[Use cases](/v0.1/docs/use_cases/)[Integrations](/v0.1/docs/integrations/platforms/)[API Reference](https://api.js.langchain.com)

[More](#)

*   [People](/v0.1/docs/people/)
*   [Community](/v0.1/docs/community/)
*   [Tutorials](/v0.1/docs/additional_resources/tutorials/)
*   [Contributing](/v0.1/docs/contributing/)

[v0.1](#)

*   [v0.2](https://js.langchain.com/v0.2/docs/introduction)
*   [v0.1](/v0.1/docs/get_started/introduction/)

[🦜🔗](#)

*   [LangSmith](https://smith.langchain.com)
*   [LangSmith Docs](https://docs.smith.langchain.com)
*   [LangChain Hub](https://smith.langchain.com/hub)
*   [LangServe](https://github.com/langchain-ai/langserve)
*   [Python Docs](https://python.langchain.com/)

[Chat](https://chatjs.langchain.com)[](https://github.com/langchain-ai/langchainjs)

Search

*   [Get started](/v0.1/docs/get_started/)
    
    *   [Introduction](/v0.1/docs/get_started/introduction/)
    *   [Installation](/v0.1/docs/get_started/installation/)
    *   [Quickstart](/v0.1/docs/get_started/quickstart/)
*   [LangChain Expression Language](/v0.1/docs/expression_language/)
    
    *   [Get started](/v0.1/docs/expression_language/get_started/)
    *   [Why use LCEL?](/v0.1/docs/expression_language/why/)
    *   [Interface](/v0.1/docs/expression_language/interface/)
    *   [Streaming](/v0.1/docs/expression_language/streaming/)
    *   [How to](/v0.1/docs/expression_language/how_to/routing/)
        
    *   [Cookbook](/v0.1/docs/expression_language/cookbook/)
        
    *   [LangChain Expression Language (LCEL)](/v0.1/docs/expression_language/)
*   [Modules](/v0.1/docs/modules/)
    
    *   [Model I/O](/v0.1/docs/modules/model_io/)
        
    *   [Retrieval](/v0.1/docs/modules/data_connection/)
        
        *   [Document loaders](/v0.1/docs/modules/data_connection/document_loaders/)
            
        *   [Text Splitters](/v0.1/docs/modules/data_connection/document_transformers/)
            
        *   [Retrievers](/v0.1/docs/modules/data_connection/retrievers/)
            
        *   [Retrieval](/v0.1/docs/modules/data_connection/)
        *   [Text embedding models](/v0.1/docs/modules/data_connection/text_embedding/)
            
        *   [Vector stores](/v0.1/docs/modules/data_connection/vectorstores/)
            
            *   [Custom vectorstores](/v0.1/docs/modules/data_connection/vectorstores/custom/)
        *   [Indexing](/v0.1/docs/modules/data_connection/indexing/)
        *   [Experimental](/v0.1/docs/modules/data_connection/experimental/multimodal_embeddings/google_vertex_ai/)
            
    *   [Chains](/v0.1/docs/modules/chains/)
    *   [Agents](/v0.1/docs/modules/agents/)
        
    *   [More](/v0.1/docs/modules/memory/)
        
*   [Security](/v0.1/docs/security/)
*   [Guides](/v0.1/docs/guides/)
    
*   [Ecosystem](/v0.1/docs/ecosystem/)
    
*   [LangGraph](/v0.1/docs/langgraph/)
*   * * *
    

*   [](/v0.1/)
*   [Modules](/v0.1/docs/modules/)
*   [Retrieval](/v0.1/docs/modules/data_connection/)
*   Vector stores

On this page

Vector stores
=============

info

Head to [Integrations](/v0.1/docs/integrations/vectorstores/) for documentation on built-in integrations with vectorstore providers.

One of the most common ways to store and search over unstructured data is to embed it and store the resulting embedding vectors, and then at query time to embed the unstructured query and retrieve the embedding vectors that are 'most similar' to the embedded query. A vector store takes care of storing embedded data and performing vector search for you.

Get started[​](#get-started "Direct link to Get started")
---------------------------------------------------------

This walkthrough showcases basic functionality related to VectorStores. A key part of working with vector stores is creating the vector to put in them, which is usually created via embeddings. Therefore, it is recommended that you familiarize yourself with the [text embedding model](/v0.1/docs/modules/data_connection/text_embedding/) interfaces before diving into this.

This walkthrough uses a basic, unoptimized implementation called MemoryVectorStore that stores embeddings in-memory and does an exact, linear search for the most similar embeddings.

Usage[​](#usage "Direct link to Usage")
---------------------------------------

### Create a new index from texts[​](#create-a-new-index-from-texts "Direct link to Create a new index from texts")

tip

See [this section for general instructions on installing integration packages](/v0.1/docs/get_started/installation/#installing-integration-packages).

*   npm
*   Yarn
*   pnpm

    npm install @langchain/openai

    yarn add @langchain/openai

    pnpm add @langchain/openai

    import { MemoryVectorStore } from "langchain/vectorstores/memory";import { OpenAIEmbeddings } from "@langchain/openai";const vectorStore = await MemoryVectorStore.fromTexts(  ["Hello world", "Bye bye", "hello nice world"],  [{ id: 2 }, { id: 1 }, { id: 3 }],  new OpenAIEmbeddings());const resultOne = await vectorStore.similaritySearch("hello world", 1);console.log(resultOne);/*  [    Document {      pageContent: "Hello world",      metadata: { id: 2 }    }  ]*/

#### API Reference:

*   [MemoryVectorStore](https://api.js.langchain.com/classes/langchain_vectorstores_memory.MemoryVectorStore.html) from `langchain/vectorstores/memory`
*   [OpenAIEmbeddings](https://api.js.langchain.com/classes/langchain_openai.OpenAIEmbeddings.html) from `@langchain/openai`

### Create a new index from a loader[​](#create-a-new-index-from-a-loader "Direct link to Create a new index from a loader")

    import { MemoryVectorStore } from "langchain/vectorstores/memory";import { OpenAIEmbeddings } from "@langchain/openai";import { TextLoader } from "langchain/document_loaders/fs/text";// Create docs with a loaderconst loader = new TextLoader("src/document_loaders/example_data/example.txt");const docs = await loader.load();// Load the docs into the vector storeconst vectorStore = await MemoryVectorStore.fromDocuments(  docs,  new OpenAIEmbeddings());// Search for the most similar documentconst resultOne = await vectorStore.similaritySearch("hello world", 1);console.log(resultOne);/*  [    Document {      pageContent: "Hello world",      metadata: { id: 2 }    }  ]*/

#### API Reference:

*   [MemoryVectorStore](https://api.js.langchain.com/classes/langchain_vectorstores_memory.MemoryVectorStore.html) from `langchain/vectorstores/memory`
*   [OpenAIEmbeddings](https://api.js.langchain.com/classes/langchain_openai.OpenAIEmbeddings.html) from `@langchain/openai`
*   [TextLoader](https://api.js.langchain.com/classes/langchain_document_loaders_fs_text.TextLoader.html) from `langchain/document_loaders/fs/text`

Here is the current base interface all vector stores share:

    interface VectorStore {  /**   * Add more documents to an existing VectorStore.   * Some providers support additional parameters, e.g. to associate custom ids   * with added documents or to change the batch size of bulk inserts.   * Returns an array of ids for the documents or nothing.   */  addDocuments(    documents: Document[],    options?: Record<string, any>  ): Promise<string[] | void>;  /**   * Search for the most similar documents to a query   */  similaritySearch(    query: string,    k?: number,    filter?: object | undefined  ): Promise<Document[]>;  /**   * Search for the most similar documents to a query,   * and return their similarity score   */  similaritySearchWithScore(    query: string,    k = 4,    filter: object | undefined = undefined  ): Promise<[object, number][]>;  /**   * Turn a VectorStore into a Retriever   */  asRetriever(k?: number): BaseRetriever;  /**   * Delete embedded documents from the vector store matching the passed in parameter.   * Not supported by every provider.   */  delete(params?: Record<string, any>): Promise<void>;  /**   * Advanced: Add more documents to an existing VectorStore,   * when you already have their embeddings   */  addVectors(    vectors: number[][],    documents: Document[],    options?: Record<string, any>  ): Promise<string[] | void>;  /**   * Advanced: Search for the most similar documents to a query,   * when you already have the embedding of the query   */  similaritySearchVectorWithScore(    query: number[],    k: number,    filter?: object  ): Promise<[Document, number][]>;}

You can create a vector store from a list of [Documents](https://api.js.langchain.com/classes/langchain_core_documents.Document.html), or from a list of texts and their corresponding metadata. You can also create a vector store from an existing index, the signature of this method depends on the vector store you're using, check the documentation of the vector store you're interested in.

    abstract class BaseVectorStore implements VectorStore {  static fromTexts(    texts: string[],    metadatas: object[] | object,    embeddings: EmbeddingsInterface,    dbConfig: Record<string, any>  ): Promise<VectorStore>;  static fromDocuments(    docs: Document[],    embeddings: EmbeddingsInterface,    dbConfig: Record<string, any>  ): Promise<VectorStore>;}

Which one to pick?[​](#which-one-to-pick "Direct link to Which one to pick?")
-----------------------------------------------------------------------------

Here's a quick guide to help you pick the right vector store for your use case:

*   If you're after something that can just run inside your Node.js application, in-memory, without any other servers to stand up, then go for [HNSWLib](/v0.1/docs/integrations/vectorstores/hnswlib/), [Faiss](/v0.1/docs/integrations/vectorstores/faiss/), [LanceDB](/v0.1/docs/integrations/vectorstores/lancedb/) or [CloseVector](/v0.1/docs/integrations/vectorstores/closevector/)
*   If you're looking for something that can run in-memory in browser-like environments, then go for [MemoryVectorStore](/v0.1/docs/integrations/vectorstores/memory/) or [CloseVector](/v0.1/docs/integrations/vectorstores/closevector/)
*   If you come from Python and you were looking for something similar to FAISS, try [HNSWLib](/v0.1/docs/integrations/vectorstores/hnswlib/) or [Faiss](/v0.1/docs/integrations/vectorstores/faiss/)
*   If you're looking for an open-source full-featured vector database that you can run locally in a docker container, then go for [Chroma](/v0.1/docs/integrations/vectorstores/chroma/)
*   If you're looking for an open-source vector database that offers low-latency, local embedding of documents and supports apps on the edge, then go for [Zep](/v0.1/docs/integrations/vectorstores/zep/)
*   If you're looking for an open-source production-ready vector database that you can run locally (in a docker container) or hosted in the cloud, then go for [Weaviate](/v0.1/docs/integrations/vectorstores/weaviate/).
*   If you're using Supabase already then look at the [Supabase](/v0.1/docs/integrations/vectorstores/supabase/) vector store to use the same Postgres database for your embeddings too
*   If you're looking for a production-ready vector store you don't have to worry about hosting yourself, then go for [Pinecone](/v0.1/docs/integrations/vectorstores/pinecone/)
*   If you are already utilizing SingleStore, or if you find yourself in need of a distributed, high-performance database, you might want to consider the [SingleStore](/v0.1/docs/integrations/vectorstores/singlestore/) vector store.
*   If you are looking for an online MPP (Massively Parallel Processing) data warehousing service, you might want to consider the [AnalyticDB](/v0.1/docs/integrations/vectorstores/analyticdb/) vector store.
*   If you're in search of a cost-effective vector database that allows run vector search with SQL, look no further than [MyScale](/v0.1/docs/integrations/vectorstores/myscale/).
*   If you're in search of a vector database that you can load from both the browser and server side, check out [CloseVector](/v0.1/docs/integrations/vectorstores/closevector/). It's a vector database that aims to be cross-platform.
*   If you're looking for a scalable, open-source columnar database with excellent performance for analytical queries, then consider [ClickHouse](/v0.1/docs/integrations/vectorstores/clickhouse/).

* * *

#### Help us out by providing feedback on this documentation page:

[

Previous

Adding a timeout

](/v0.1/docs/modules/data_connection/text_embedding/timeouts/)[

Next

Custom vectorstores

](/v0.1/docs/modules/data_connection/vectorstores/custom/)

*   [Get started](#get-started)
*   [Usage](#usage)
    *   [Create a new index from texts](#create-a-new-index-from-texts)
    *   [Create a new index from a loader](#create-a-new-index-from-a-loader)
*   [Which one to pick?](#which-one-to-pick)

Community

*   [Discord](https://discord.gg/cU2adEyC7w)
*   [Twitter](https://twitter.com/LangChainAI)

GitHub

*   [Python](https://github.com/langchain-ai/langchain)
*   [JS/TS](https://github.com/langchain-ai/langchainjs)

More

*   [Homepage](https://langchain.com)
*   [Blog](https://blog.langchain.dev)

Copyright © 2024 LangChain, Inc.