Zep Cloud
Recall, understand, and extract data from chat histories. Power personalized AI experiences.
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.
Usage
In the examples below, we're using Zep's auto-embedding feature which automatically embeds documents on the Zep server using low-latency embedding models.
Note
- These examples use Zep's async interfaces. Call sync interfaces by removing the
a
prefix from the method names.
Load or create a Collection from documents
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
Simarility Search Query over the Collection
# query it
query = "what is the structure of our solar system?"
docs_scores = await vs.asimilarity_search_with_relevance_scores(query, k=3)
# print results
for d, s in docs_scores:
print(d.page_content, " -> ", s, "\n====\n")
the positions of the two principal planets, (and these the most
necessary for the navigator,) Jupiter and Saturn, require each not less
than one hundred and sixteen tables. Yet it is not only necessary to
predict the position of these bodies, but it is likewise expedient to
tabulate the motions of the four satellites of Jupiter, to predict the
exact times at which they enter his shadow, and at which their shadows
cross his disc, as well as the times at which they are interposed -> 0.78691166639328
====
are reduced to a system of wheel-work. We are, nevertheless, not without
hopes of conveying, even to readers unskilled in mathematics, some
satisfactory notions of a general nature on this subject.
_Thirdly_, To explain the actual state of the machinery at the present
time; what progress has been made towards its completion; and what are
the probable causes of those delays in its progress, which must be a
subject of regret to all friends of science. We shall indicate what -> 0.7853284478187561
====
from the improved state of astronomy, he found it necessary to recompute
these tables in 1821.
Although it is now about thirty years since the discovery of the four
new planets, Ceres, Pallas, Juno, and Vesta, it was not till recently
that tables of their motions were published. They have lately appeared
in Encke's Ephemeris.
We have thus attempted to convey some notion (though necessarily a very
inadequate one) of the immense extent of numerical tables which it has -> 0.7840130925178528
====