!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)

You are viewing the **preview** v0.2 docs. View the **stable** v0.1 docs [here](/v0.1/docs/get_started/introduction/). Leave feedback on the v0.2 docs [here](https://github.com/langchain-ai/langchainjs/discussions/5386).

[

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

](/v0.2/)[Integrations](/v0.2/docs/integrations/platforms/)[API Reference](https://v02.api.js.langchain.com)

[More](#)

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

[v0.2](#)

*   [v0.2](/v0.2/docs/introduction)
*   [v0.1](https://js.langchain.com/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

*   [Providers](/v0.2/docs/integrations/platforms/)
    
    *   [Providers](/v0.2/docs/integrations/platforms/)
    *   [Anthropic](/v0.2/docs/integrations/platforms/anthropic)
    *   [AWS](/v0.2/docs/integrations/platforms/aws)
    *   [Google](/v0.2/docs/integrations/platforms/google)
    *   [Microsoft](/v0.2/docs/integrations/platforms/microsoft)
    *   [OpenAI](/v0.2/docs/integrations/platforms/openai)
*   [Components](/v0.2/docs/integrations/components)
    
    *   [Chat models](/v0.2/docs/integrations/chat/)
        
    *   [LLMs](/v0.2/docs/integrations/llms/)
        
    *   [Embedding models](/v0.2/docs/integrations/text_embedding)
        
    *   [Document loaders](/v0.2/docs/integrations/document_loaders)
        
    *   [Document transformers](/v0.2/docs/integrations/document_transformers)
        
    *   [Vector stores](/v0.2/docs/integrations/vectorstores)
        
        *   [Memory](/v0.2/docs/integrations/vectorstores/memory)
        *   [AnalyticDB](/v0.2/docs/integrations/vectorstores/analyticdb)
        *   [Astra DB](/v0.2/docs/integrations/vectorstores/astradb)
        *   [Azure AI Search](/v0.2/docs/integrations/vectorstores/azure_aisearch)
        *   [Azure Cosmos DB](/v0.2/docs/integrations/vectorstores/azure_cosmosdb)
        *   [Cassandra](/v0.2/docs/integrations/vectorstores/cassandra)
        *   [Chroma](/v0.2/docs/integrations/vectorstores/chroma)
        *   [ClickHouse](/v0.2/docs/integrations/vectorstores/clickhouse)
        *   [CloseVector](/v0.2/docs/integrations/vectorstores/closevector)
        *   [Cloudflare Vectorize](/v0.2/docs/integrations/vectorstores/cloudflare_vectorize)
        *   [Convex](/v0.2/docs/integrations/vectorstores/convex)
        *   [Couchbase](/v0.2/docs/integrations/vectorstores/couchbase)
        *   [Elasticsearch](/v0.2/docs/integrations/vectorstores/elasticsearch)
        *   [Faiss](/v0.2/docs/integrations/vectorstores/faiss)
        *   [Google Vertex AI Matching Engine](/v0.2/docs/integrations/vectorstores/googlevertexai)
        *   [SAP HANA Cloud Vector Engine](/v0.2/docs/integrations/vectorstores/hanavector)
        *   [HNSWLib](/v0.2/docs/integrations/vectorstores/hnswlib)
        *   [LanceDB](/v0.2/docs/integrations/vectorstores/lancedb)
        *   [Milvus](/v0.2/docs/integrations/vectorstores/milvus)
        *   [Momento Vector Index (MVI)](/v0.2/docs/integrations/vectorstores/momento_vector_index)
        *   [MongoDB Atlas](/v0.2/docs/integrations/vectorstores/mongodb_atlas)
        *   [MyScale](/v0.2/docs/integrations/vectorstores/myscale)
        *   [Neo4j Vector Index](/v0.2/docs/integrations/vectorstores/neo4jvector)
        *   [Neon Postgres](/v0.2/docs/integrations/vectorstores/neon)
        *   [OpenSearch](/v0.2/docs/integrations/vectorstores/opensearch)
        *   [PGVector](/v0.2/docs/integrations/vectorstores/pgvector)
        *   [Pinecone](/v0.2/docs/integrations/vectorstores/pinecone)
        *   [Prisma](/v0.2/docs/integrations/vectorstores/prisma)
        *   [Qdrant](/v0.2/docs/integrations/vectorstores/qdrant)
        *   [Redis](/v0.2/docs/integrations/vectorstores/redis)
        *   [Rockset](/v0.2/docs/integrations/vectorstores/rockset)
        *   [SingleStore](/v0.2/docs/integrations/vectorstores/singlestore)
        *   [Supabase](/v0.2/docs/integrations/vectorstores/supabase)
        *   [Tigris](/v0.2/docs/integrations/vectorstores/tigris)
        *   [Turbopuffer](/v0.2/docs/integrations/vectorstores/turbopuffer)
        *   [TypeORM](/v0.2/docs/integrations/vectorstores/typeorm)
        *   [Typesense](/v0.2/docs/integrations/vectorstores/typesense)
        *   [Upstash Vector](/v0.2/docs/integrations/vectorstores/upstash)
        *   [USearch](/v0.2/docs/integrations/vectorstores/usearch)
        *   [Vectara](/v0.2/docs/integrations/vectorstores/vectara)
        *   [Vercel Postgres](/v0.2/docs/integrations/vectorstores/vercel_postgres)
        *   [Voy](/v0.2/docs/integrations/vectorstores/voy)
        *   [Weaviate](/v0.2/docs/integrations/vectorstores/weaviate)
        *   [Xata](/v0.2/docs/integrations/vectorstores/xata)
        *   [Zep](/v0.2/docs/integrations/vectorstores/zep)
    *   [Retrievers](/v0.2/docs/integrations/retrievers)
        
    *   [Tools](/v0.2/docs/integrations/tools)
        
    *   [Toolkits](/v0.2/docs/integrations/toolkits)
        
    *   [Stores](/v0.2/docs/integrations/stores/)
        

*   [](/v0.2/)
*   [Components](/v0.2/docs/integrations/components)
*   [Vector stores](/v0.2/docs/integrations/vectorstores)
*   Momento Vector Index (MVI)

On this page

Momento Vector Index (MVI)
==========================

[MVI](https://gomomento.com): the most productive, easiest to use, serverless vector index for your data. To get started with MVI, simply sign up for an account. There's no need to handle infrastructure, manage servers, or be concerned about scaling. MVI is a service that scales automatically to meet your needs. Whether in Node.js, browser, or edge, Momento has you covered.

To sign up and access MVI, visit the [Momento Console](https://console.gomomento.com).

Setup[​](#setup "Direct link to Setup")
---------------------------------------

1.  Sign up for an API key in the [Momento Console](https://console.gomomento.com/).
    
2.  Install the SDK for your environment.
    
    2.1. For **Node.js**:
    
    *   npm
    *   Yarn
    *   pnpm
    
        npm install @gomomento/sdk
    
        yarn add @gomomento/sdk
    
        pnpm add @gomomento/sdk
    
    2.2. For **browser or edge environments**:
    
    *   npm
    *   Yarn
    *   pnpm
    
        npm install @gomomento/sdk-web
    
        yarn add @gomomento/sdk-web
    
        pnpm add @gomomento/sdk-web
    
3.  Setup Env variables for Momento before running the code
    
    3.1 OpenAI
    
        export OPENAI_API_KEY=YOUR_OPENAI_API_KEY_HERE
    
    3.2 Momento
    
        export MOMENTO_API_KEY=YOUR_MOMENTO_API_KEY_HERE # https://console.gomomento.com
    

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

tip

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

*   npm
*   Yarn
*   pnpm

    npm install @langchain/openai @langchain/community

    yarn add @langchain/openai @langchain/community

    pnpm add @langchain/openai @langchain/community

### Index documents using `fromTexts` and search[​](#index-documents-using-fromtexts-and-search "Direct link to index-documents-using-fromtexts-and-search")

This example demonstrates using the `fromTexts` method to instantiate the vector store and index documents. If the index does not exist, then it will be created. If the index already exists, then the documents will be added to the existing index.

The `ids` are optional; if you omit them, then Momento will generate UUIDs for you.

    import { MomentoVectorIndex } from "@langchain/community/vectorstores/momento_vector_index";// For browser/edge, adjust this to import from "@gomomento/sdk-web";import {  PreviewVectorIndexClient,  VectorIndexConfigurations,  CredentialProvider,} from "@gomomento/sdk";import { OpenAIEmbeddings } from "@langchain/openai";import { sleep } from "langchain/util/time";const vectorStore = await MomentoVectorIndex.fromTexts(  ["hello world", "goodbye world", "salutations world", "farewell world"],  {},  new OpenAIEmbeddings(),  {    client: new PreviewVectorIndexClient({      configuration: VectorIndexConfigurations.Laptop.latest(),      credentialProvider: CredentialProvider.fromEnvironmentVariable({        environmentVariableName: "MOMENTO_API_KEY",      }),    }),    indexName: "langchain-example-index",  },  { ids: ["1", "2", "3", "4"] });// because indexing is async, wait for it to finish to search directly afterawait sleep();const response = await vectorStore.similaritySearch("hello", 2);console.log(response);/*[  Document { pageContent: 'hello world', metadata: {} },  Document { pageContent: 'salutations world', metadata: {} }]*/

#### API Reference:

*   [MomentoVectorIndex](https://v02.api.js.langchain.com/classes/langchain_community_vectorstores_momento_vector_index.MomentoVectorIndex.html) from `@langchain/community/vectorstores/momento_vector_index`
*   [OpenAIEmbeddings](https://v02.api.js.langchain.com/classes/langchain_openai.OpenAIEmbeddings.html) from `@langchain/openai`
*   [sleep](https://v02.api.js.langchain.com/functions/langchain_util_time.sleep.html) from `langchain/util/time`

### Index documents using `fromDocuments` and search[​](#index-documents-using-fromdocuments-and-search "Direct link to index-documents-using-fromdocuments-and-search")

Similar to the above, this example demonstrates using the `fromDocuments` method to instantiate the vector store and index documents. If the index does not exist, then it will be created. If the index already exists, then the documents will be added to the existing index.

Using `fromDocuments` allows you to seamlessly chain the various document loaders with indexing.

    import { MomentoVectorIndex } from "@langchain/community/vectorstores/momento_vector_index";// For browser/edge, adjust this to import from "@gomomento/sdk-web";import {  PreviewVectorIndexClient,  VectorIndexConfigurations,  CredentialProvider,} from "@gomomento/sdk";import { OpenAIEmbeddings } from "@langchain/openai";import { TextLoader } from "langchain/document_loaders/fs/text";import { sleep } from "langchain/util/time";// Create docs with a loaderconst loader = new TextLoader("src/document_loaders/example_data/example.txt");const docs = await loader.load();const vectorStore = await MomentoVectorIndex.fromDocuments(  docs,  new OpenAIEmbeddings(),  {    client: new PreviewVectorIndexClient({      configuration: VectorIndexConfigurations.Laptop.latest(),      credentialProvider: CredentialProvider.fromEnvironmentVariable({        environmentVariableName: "MOMENTO_API_KEY",      }),    }),    indexName: "langchain-example-index",  });// because indexing is async, wait for it to finish to search directly afterawait sleep();// Search for the most similar documentconst response = await vectorStore.similaritySearch("hello", 1);console.log(response);/*[  Document {    pageContent: 'Foo\nBar\nBaz\n\n',    metadata: { source: 'src/document_loaders/example_data/example.txt' }  }]*/

#### API Reference:

*   [MomentoVectorIndex](https://v02.api.js.langchain.com/classes/langchain_community_vectorstores_momento_vector_index.MomentoVectorIndex.html) from `@langchain/community/vectorstores/momento_vector_index`
*   [OpenAIEmbeddings](https://v02.api.js.langchain.com/classes/langchain_openai.OpenAIEmbeddings.html) from `@langchain/openai`
*   [TextLoader](https://v02.api.js.langchain.com/classes/langchain_document_loaders_fs_text.TextLoader.html) from `langchain/document_loaders/fs/text`
*   [sleep](https://v02.api.js.langchain.com/functions/langchain_util_time.sleep.html) from `langchain/util/time`

### Search from an existing collection[​](#search-from-an-existing-collection "Direct link to Search from an existing collection")

    import { MomentoVectorIndex } from "@langchain/community/vectorstores/momento_vector_index";// For browser/edge, adjust this to import from "@gomomento/sdk-web";import {  PreviewVectorIndexClient,  VectorIndexConfigurations,  CredentialProvider,} from "@gomomento/sdk";import { OpenAIEmbeddings } from "@langchain/openai";const vectorStore = new MomentoVectorIndex(new OpenAIEmbeddings(), {  client: new PreviewVectorIndexClient({    configuration: VectorIndexConfigurations.Laptop.latest(),    credentialProvider: CredentialProvider.fromEnvironmentVariable({      environmentVariableName: "MOMENTO_API_KEY",    }),  }),  indexName: "langchain-example-index",});const response = await vectorStore.similaritySearch("hello", 1);console.log(response);/*[  Document {    pageContent: 'Foo\nBar\nBaz\n\n',    metadata: { source: 'src/document_loaders/example_data/example.txt' }  }]*/

#### API Reference:

*   [MomentoVectorIndex](https://v02.api.js.langchain.com/classes/langchain_community_vectorstores_momento_vector_index.MomentoVectorIndex.html) from `@langchain/community/vectorstores/momento_vector_index`
*   [OpenAIEmbeddings](https://v02.api.js.langchain.com/classes/langchain_openai.OpenAIEmbeddings.html) from `@langchain/openai`

* * *

#### Was this page helpful?

  

#### You can leave detailed feedback [on GitHub](https://github.com/langchain-ai/langchainjs/issues/new?assignees=&labels=03+-+Documentation&projects=&template=documentation.yml&title=DOC%3A+%3CPlease+write+a+comprehensive+title+after+the+%27DOC%3A+%27+prefix%3E).

[

Previous

Milvus

](/v0.2/docs/integrations/vectorstores/milvus)[

Next

MongoDB Atlas

](/v0.2/docs/integrations/vectorstores/mongodb_atlas)

*   [Setup](#setup)
*   [Usage](#usage)
    *   [Index documents using `fromTexts` and search](#index-documents-using-fromtexts-and-search)
    *   [Index documents using `fromDocuments` and search](#index-documents-using-fromdocuments-and-search)
    *   [Search from an existing collection](#search-from-an-existing-collection)

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.