!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

*   [Providers](/v0.1/docs/integrations/platforms/)
    
    *   [Providers](/v0.1/docs/integrations/platforms/)
    *   [Anthropic](/v0.1/docs/integrations/platforms/anthropic/)
    *   [AWS](/v0.1/docs/integrations/platforms/aws/)
    *   [Google](/v0.1/docs/integrations/platforms/google/)
    *   [Microsoft](/v0.1/docs/integrations/platforms/microsoft/)
    *   [OpenAI](/v0.1/docs/integrations/platforms/openai/)
*   [Components](/v0.1/docs/integrations/components/)
    
    *   [LLMs](/v0.1/docs/integrations/llms/)
        
    *   [Chat models](/v0.1/docs/integrations/chat/)
        
    *   [Document loaders](/v0.1/docs/integrations/document_loaders/)
        
    *   [Document transformers](/v0.1/docs/integrations/document_transformers/)
        
    *   [Document compressors](/v0.1/docs/integrations/document_compressors/)
        
    *   [Text embedding models](/v0.1/docs/integrations/text_embedding/)
        
    *   [Vector stores](/v0.1/docs/integrations/vectorstores/)
        
    *   [Retrievers](/v0.1/docs/integrations/retrievers/)
        
        *   [Knowledge Bases for Amazon Bedrock](/v0.1/docs/integrations/retrievers/bedrock-knowledge-bases/)
        *   [Chaindesk Retriever](/v0.1/docs/integrations/retrievers/chaindesk-retriever/)
        *   [ChatGPT Plugin Retriever](/v0.1/docs/integrations/retrievers/chatgpt-retriever-plugin/)
        *   [Dria Retriever](/v0.1/docs/integrations/retrievers/dria/)
        *   [Exa Search](/v0.1/docs/integrations/retrievers/exa/)
        *   [HyDE Retriever](/v0.1/docs/integrations/retrievers/hyde/)
        *   [Amazon Kendra Retriever](/v0.1/docs/integrations/retrievers/kendra-retriever/)
        *   [Metal Retriever](/v0.1/docs/integrations/retrievers/metal-retriever/)
        *   [Supabase Hybrid Search](/v0.1/docs/integrations/retrievers/supabase-hybrid/)
        *   [Tavily Search API](/v0.1/docs/integrations/retrievers/tavily/)
        *   [Time-Weighted Retriever](/v0.1/docs/integrations/retrievers/time-weighted-retriever/)
        *   [Vector Store](/v0.1/docs/integrations/retrievers/vectorstore/)
        *   [Vespa Retriever](/v0.1/docs/integrations/retrievers/vespa-retriever/)
        *   [Zep Retriever](/v0.1/docs/integrations/retrievers/zep-retriever/)
    *   [Tools](/v0.1/docs/integrations/tools/)
        
    *   [Agents and toolkits](/v0.1/docs/integrations/toolkits/)
        
    *   [Chat Memory](/v0.1/docs/integrations/chat_memory/)
        
    *   [Stores](/v0.1/docs/integrations/stores/)
        

*   [](/v0.1/)
*   [Components](/v0.1/docs/integrations/components/)
*   [Retrievers](/v0.1/docs/integrations/retrievers/)
*   Zep Retriever

Zep Retriever
=============

> [Zep](https://www.getzep.com) is a long-term memory service for AI Assistant apps. With Zep, you can provide AI assistants with the ability to recall past conversations, no matter how distant, while also reducing hallucinations, latency, and cost.

> Interested in Zep Cloud? See [Zep Cloud Installation Guide](https://help.getzep.com/sdks), [Zep Cloud Retriever Example](https://help.getzep.com/langchain/examples/rag-message-history-example)

This example shows how to use the Zep Retriever in a retrieval chain to retrieve documents from Zep memory store.

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

tip

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

*   npm
*   Yarn
*   pnpm

    npm i @getzep/zep-js @langchain/community

    yarn add @getzep/zep-js @langchain/community

    pnpm add @getzep/zep-js @langchain/community

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

    import { ZepRetriever } from "@langchain/community/retrievers/zep";import { ZepMemory } from "@langchain/community/memory/zep";import { Memory as MemoryModel, Message } from "@getzep/zep-js";import { randomUUID } from "crypto";function sleep(ms: number) {  // eslint-disable-next-line no-promise-executor-return  return new Promise((resolve) => setTimeout(resolve, ms));}export const run = async () => {  const zepConfig = {    url: process.env.ZEP_URL || "http://localhost:8000",    sessionId: `session_${randomUUID()}`,  };  console.log(`Zep Config: ${JSON.stringify(zepConfig)}`);  const memory = new ZepMemory({    baseURL: zepConfig.url,    sessionId: zepConfig.sessionId,  });  // Generate chat messages about traveling to France  const chatMessages = [    {      role: "AI",      message: "Bonjour! How can I assist you with your travel plans today?",    },    { role: "User", message: "I'm planning a trip to France." },    {      role: "AI",      message: "That sounds exciting! What cities are you planning to visit?",    },    { role: "User", message: "I'm thinking of visiting Paris and Nice." },    {      role: "AI",      message: "Great choices! Are you interested in any specific activities?",    },    { role: "User", message: "I would love to visit some vineyards." },    {      role: "AI",      message:        "France has some of the best vineyards in the world. I can help you find some.",    },    { role: "User", message: "That would be great!" },    { role: "AI", message: "Do you prefer red or white wine?" },    { role: "User", message: "I prefer red wine." },    {      role: "AI",      message:        "Perfect! I'll find some vineyards that are known for their red wines.",    },    { role: "User", message: "Thank you, that would be very helpful." },    {      role: "AI",      message:        "You're welcome! I'll also look up some French wine etiquette for you.",    },    {      role: "User",      message: "That sounds great. I can't wait to start my trip!",    },    {      role: "AI",      message:        "I'm sure you'll have a fantastic time. Do you have any other questions about your trip?",    },    { role: "User", message: "Not at the moment, thank you for your help!" },  ];  const zepClient = await memory.zepClientPromise;  if (!zepClient) {    throw new Error("ZepClient is not initialized");  }  // Add chat messages to memory  for (const chatMessage of chatMessages) {    let m: MemoryModel;    if (chatMessage.role === "AI") {      m = new MemoryModel({        messages: [new Message({ role: "ai", content: chatMessage.message })],      });    } else {      m = new MemoryModel({        messages: [          new Message({ role: "human", content: chatMessage.message }),        ],      });    }    await zepClient.memory.addMemory(zepConfig.sessionId, m);  }  // Wait for messages to be summarized, enriched, embedded and indexed.  await sleep(10000);  // Simple similarity search  const query = "Can I drive red cars in France?";  const retriever = new ZepRetriever({ ...zepConfig, topK: 3 });  const docs = await retriever.invoke(query);  console.log("Simple similarity search");  console.log(JSON.stringify(docs, null, 2));  // mmr reranking search  const mmrRetriever = new ZepRetriever({    ...zepConfig,    topK: 3,    searchType: "mmr",    mmrLambda: 0.5,  });  const mmrDocs = await mmrRetriever.invoke(query);  console.log("MMR reranking search");  console.log(JSON.stringify(mmrDocs, null, 2));  // summary search with mmr reranking  const mmrSummaryRetriever = new ZepRetriever({    ...zepConfig,    topK: 3,    searchScope: "summary",    searchType: "mmr",    mmrLambda: 0.5,  });  const mmrSummaryDocs = await mmrSummaryRetriever.invoke(query);  console.log("Summary search with MMR reranking");  console.log(JSON.stringify(mmrSummaryDocs, null, 2));  // Filtered search  const filteredRetriever = new ZepRetriever({    ...zepConfig,    topK: 3,    filter: {      where: { jsonpath: '$.system.entities[*] ? (@.Label == "GPE")' },    },  });  const filteredDocs = await filteredRetriever.invoke(query);  console.log("Filtered search");  console.log(JSON.stringify(filteredDocs, null, 2));};

#### API Reference:

*   [ZepRetriever](https://api.js.langchain.com/classes/langchain_community_retrievers_zep.ZepRetriever.html) from `@langchain/community/retrievers/zep`
*   [ZepMemory](https://api.js.langchain.com/classes/langchain_community_memory_zep.ZepMemory.html) from `@langchain/community/memory/zep`

* * *

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

[

Previous

Vespa Retriever

](/v0.1/docs/integrations/retrievers/vespa-retriever/)[

Next

Tools

](/v0.1/docs/integrations/tools/)

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.