Zep 开源内存
¥Zep Open Source Memory
回忆、理解并提取聊天记录中的数据。增强个性化 AI 体验。
¥Recall, understand, and extract data from chat histories. Power personalized AI experiences.
Zep 是一项面向 AI 助手应用的长期内存服务。使用 Zep,你可以为 AI 助手提供回忆过去对话的能力,无论对话有多久远,同时还能减少幻觉、延迟和成本。
¥Zep 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.
Zep 的工作原理
¥How Zep works
Zep 会保存并调用聊天记录,并自动根据这些聊天记录生成摘要和其他数据。它还嵌入了消息和摘要,使你能够在 Zep 中搜索过去对话中的相关上下文。Zep 以异步方式执行所有这些操作,确保这些操作不会影响用户的聊天体验。数据持久化到数据库,允许你在增长需求时进行扩展。
¥Zep persists and recalls chat histories, and automatically generates summaries and other artifacts from these chat histories. It also embeds messages and summaries, enabling you to search Zep for relevant context from past conversations. Zep does all of this asynchronously, ensuring these operations don't impact your user's chat experience. Data is persisted to database, allowing you to scale out when growth demands.
Zep 还提供了一个简单易用的文档向量搜索抽象,称为“文档集合 (Document Collections)”。这旨在补充 Zep 的核心内存功能,但并非设计为通用向量数据库。
¥Zep also provides a simple, easy to use abstraction for document vector search called Document Collections. This is designed to complement Zep's core memory features, but is not designed to be a general purpose vector database.
Zep 让你可以更有针对性地构建提示:
¥Zep allows you to be more intentional about constructing your prompt:
自动添加一些最近的消息,并根据你的应用自定义消息数量;
¥automatically adding a few recent messages, with the number customized for your app;
上述消息之前的近期对话摘要;
¥a summary of recent conversations prior to the messages above;
和/或从整个聊天会话中浮现的上下文相关的摘要或消息。
¥and/or contextually relevant summaries or messages surfaced from the entire chat session.
和/或来自 Zep 文档集合的相关业务数据。
¥and/or relevant Business data from Zep Document Collections.
对 Zep Cloud 感兴趣?请参阅 Zep Cloud 安装指南
¥Interested in Zep Cloud? See Zep Cloud Installation Guide
设置
¥Setup
有关如何在本地或通过自动托管服务提供商运行服务器,请参阅 Zep 开源 的说明。
¥See the instructions from Zep Open Source for running the server locally or through an automated hosting provider.
- npm
- Yarn
- pnpm
npm install @langchain/openai @langchain/community @langchain/core
yarn add @langchain/openai @langchain/community @langchain/core
pnpm add @langchain/openai @langchain/community @langchain/core
用法
¥Usage
import { ChatOpenAI } from "@langchain/openai";
import { ConversationChain } from "langchain/chains";
import { ZepMemory } from "@langchain/community/memory/zep";
import { randomUUID } from "crypto";
const sessionId = randomUUID(); // This should be unique for each user or each user's session.
const zepURL = "http://localhost:8000";
const memory = new ZepMemory({
sessionId,
baseURL: zepURL,
// This is optional. If you've enabled JWT authentication on your Zep server, you can
// pass it in here. See https://docs.getzep.com/deployment/auth
apiKey: "change_this_key",
});
const model = new ChatOpenAI({
model: "gpt-3.5-turbo",
temperature: 0,
});
const chain = new ConversationChain({ llm: model, memory });
console.log("Memory Keys:", memory.memoryKeys);
const res1 = await chain.invoke({ input: "Hi! I'm Jim." });
console.log({ res1 });
/*
{
res1: {
text: "Hello Jim! It's nice to meet you. My name is AI. How may I assist you today?"
}
}
*/
const res2 = await chain.invoke({ input: "What did I just say my name was?" });
console.log({ res2 });
/*
{
res1: {
text: "You said your name was Jim."
}
}
*/
console.log("Session ID: ", sessionId);
console.log("Memory: ", await memory.loadMemoryVariables({}));
API Reference:
- ChatOpenAI from
@langchain/openai - ConversationChain from
langchain/chains - ZepMemory from
@langchain/community/memory/zep