Zep Cloud
召回、理解并从聊天记录中提取数据。赋能个性化 AI 体验。
Zep 是 AI Assistant 应用的长期记忆服务。 使用 Zep,您可以让 AI Assistant 能够回忆起过去的对话,无论距离多远, 同时还能减少幻觉、延迟和成本。
用法
在下面的示例中,我们使用的是 Zep 的自动嵌入功能,该功能会在 Zep 服务器上使用低延迟嵌入模型自动嵌入文档。
注意
- 这些示例使用了 Zep 的异步接口。通过移除方法名中的
a前缀即可调用同步接口。
从文档加载或创建 Collection
from uuid import uuid4
from langchain_community.document_loaders import WebBaseLoader
from langchain_community.vectorstores import ZepCloudVectorStore
from langchain_text_splitters import RecursiveCharacterTextSplitter
ZEP_API_KEY = "<your zep project key>" # You can generate your zep project key from the Zep dashboard
collection_name = f"babbage{uuid4().hex}" # a unique collection name. alphanum only
# load the document
article_url = "https://www.gutenberg.org/cache/epub/71292/pg71292.txt"
loader = WebBaseLoader(article_url)
documents = loader.load()
# split it into chunks
text_splitter = RecursiveCharacterTextSplitter(chunk_size=500, chunk_overlap=0)
docs = text_splitter.split_documents(documents)
# Instantiate the VectorStore. Since the collection does not already exist in Zep,
# it will be created and populated with the documents we pass in.
vs = ZepCloudVectorStore.from_documents(
docs,
embedding=None,
collection_name=collection_name,
api_key=ZEP_API_KEY,
)
# wait for the collection embedding to complete
async def wait_for_ready(collection_name: str) -> None:
import time
from zep_cloud.client import AsyncZep
client = AsyncZep(api_key=ZEP_API_KEY)
while True:
c = await client.document.get_collection(collection_name)
print(
"Embedding status: "
f"{c.document_embedded_count}/{c.document_count} documents embedded"
)
time.sleep(1)
if c.document_embedded_count == c.document_count:
break
await wait_for_ready(collection_name)
Embedding status: 401/401 documents embedded