@getzep/zep-cloud 2.18.0 → 2.22.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. package/api/resources/document/client/Client.js +13 -13
  2. package/api/resources/graph/client/Client.js +7 -7
  3. package/api/resources/graph/resources/edge/client/Client.js +4 -4
  4. package/api/resources/graph/resources/episode/client/Client.js +5 -5
  5. package/api/resources/graph/resources/node/client/Client.js +5 -5
  6. package/api/resources/group/client/Client.js +6 -6
  7. package/api/resources/memory/client/Client.d.ts +1 -1
  8. package/api/resources/memory/client/Client.js +23 -23
  9. package/api/resources/memory/client/requests/AddMemoryRequest.d.ts +1 -1
  10. package/api/resources/user/client/Client.js +8 -8
  11. package/api/types/EntityEdge.d.ts +2 -0
  12. package/api/types/EntityNode.d.ts +2 -0
  13. package/api/types/Episode.d.ts +2 -1
  14. package/dist/api/resources/document/client/Client.js +13 -13
  15. package/dist/api/resources/graph/client/Client.js +7 -7
  16. package/dist/api/resources/graph/resources/edge/client/Client.js +4 -4
  17. package/dist/api/resources/graph/resources/episode/client/Client.js +5 -5
  18. package/dist/api/resources/graph/resources/node/client/Client.js +5 -5
  19. package/dist/api/resources/group/client/Client.js +6 -6
  20. package/dist/api/resources/memory/client/Client.d.ts +1 -1
  21. package/dist/api/resources/memory/client/Client.js +23 -23
  22. package/dist/api/resources/memory/client/requests/AddMemoryRequest.d.ts +1 -1
  23. package/dist/api/resources/user/client/Client.js +8 -8
  24. package/dist/api/types/EntityEdge.d.ts +2 -0
  25. package/dist/api/types/EntityNode.d.ts +2 -0
  26. package/dist/api/types/Episode.d.ts +2 -1
  27. package/dist/serialization/types/EntityEdge.d.ts +1 -0
  28. package/dist/serialization/types/EntityEdge.js +1 -0
  29. package/dist/serialization/types/EntityNode.d.ts +1 -0
  30. package/dist/serialization/types/EntityNode.js +1 -0
  31. package/dist/serialization/types/Episode.d.ts +1 -0
  32. package/dist/serialization/types/Episode.js +1 -0
  33. package/dist/version.d.ts +1 -1
  34. package/dist/version.js +1 -1
  35. package/examples/memory/memory_example.ts +1 -137
  36. package/package.json +1 -1
  37. package/reference.md +1 -1
  38. package/serialization/types/EntityEdge.d.ts +1 -0
  39. package/serialization/types/EntityEdge.js +1 -0
  40. package/serialization/types/EntityNode.d.ts +1 -0
  41. package/serialization/types/EntityNode.js +1 -0
  42. package/serialization/types/Episode.d.ts +1 -0
  43. package/serialization/types/Episode.js +1 -0
  44. package/version.d.ts +1 -1
  45. package/version.js +1 -1
  46. package/examples/documents/babbages_calculating_engine.txt +0 -3153
  47. package/examples/documents/index.ts +0 -188
  48. package/examples/memory/structured_data_extraction_example.ts +0 -34
@@ -1,188 +0,0 @@
1
- /**
2
- * This file demonstrates the following features of Zep:
3
- * 1. Checking the embedding status of a collection.
4
- * 2. Reading a chunk of text from a file.
5
- * 3. Printing the results of a search.
6
- * 4. Searching for documents using both text and metadata.
7
- * 5. MMR Search Re-ranking.
8
- * 6. Searching for documents similar to a given document using embeddings.
9
- * 7. Searching for non-existent documents.
10
- */
11
-
12
- import * as fs from "fs";
13
- import { faker } from "@faker-js/faker";
14
- import { ZepClient } from "../../src";
15
- import { Document } from "../../src/api/resources/document/client/Client";
16
- import { CreateDocumentRequest, DocumentSearchResult } from "../../src/api";
17
-
18
- /**
19
- * checkEmbeddingStatus checks the embedding status of a collection.
20
- * It waits until all documents in the collection are embedded.
21
- * @param client - The ZepClient instance.
22
- * @param collectionName - The name of the collection.
23
- */
24
- async function checkEmbeddingStatus(client: ZepClient, collectionName: string): Promise<void> {
25
- let c = await client.document.getCollection(collectionName);
26
-
27
- while (c.documentEmbeddedCount != c.documentCount) {
28
- console.log(`Embedding status: ${c.documentEmbeddedCount}/${c.documentCount} documents embedded`);
29
- // Wait for 1 second
30
- await new Promise((resolve) => setTimeout(resolve, 1000));
31
-
32
- // Fetch the collection again to get the updated status
33
- c = await client.document.getCollection(collectionName);
34
- }
35
- }
36
-
37
- /**
38
- * readChunkFromFile reads a chunk of text from a file.
39
- * @param file - The file to read from.
40
- * @param chunkSize - The size of the chunk to read.
41
- * @returns An array of strings, each string being a chunk of text.
42
- */
43
- function readChunkFromFile(file: string, chunkSize: number): string[] {
44
- const text = fs.readFileSync(file, "utf8");
45
- const chunks = naiveSplitText(text, chunkSize);
46
- console.log(`Splitting text into ${chunks.length} chunks of max size ${chunkSize} characters.`);
47
- return chunks;
48
- }
49
-
50
- /**
51
- * printResults prints the results of a search.
52
- * @param results - The results of the search.
53
- */
54
- function printResults(results: DocumentSearchResult[]): void {
55
- for (const result of results) {
56
- console.log(`${result.content} - ${JSON.stringify(result.metadata)} -> ${result.score}\n`);
57
- }
58
- }
59
-
60
- /**
61
- * naiveSplitText splits a text into chunks of a maximum size.
62
- * It's a simple chunke that uses paragraphs and sentences as guides.
63
- * @param text - The text to split.
64
- * @param maxChunkSize - The maximum size of a chunk.
65
- * @returns An array of strings, each string being a chunk of text.
66
- */
67
- function naiveSplitText(text: string, maxChunkSize: number): string[] {
68
- // Naive text splitter chunks document into chunks of maxChunkSize,
69
- // using paragraphs and sentences as guides.
70
-
71
- const chunks: string[] = [];
72
-
73
- // Remove extraneous whitespace
74
- text = text.split(/\s+/).join(" ");
75
-
76
- // Split into paragraphs
77
- let paragraphs = text.split("\n\n");
78
-
79
- // Clean up paragraphs
80
- paragraphs = paragraphs.map((p) => p.trim()).filter((p) => p.length > 0);
81
-
82
- for (const paragraph of paragraphs) {
83
- if (paragraph.length > 0 && paragraph.length <= maxChunkSize) {
84
- chunks.push(paragraph);
85
- } else {
86
- const sentences = paragraph.split(". ");
87
- let currentChunk = "";
88
-
89
- for (const sentence of sentences) {
90
- if (currentChunk.length + sentence.length > maxChunkSize) {
91
- chunks.push(currentChunk);
92
- currentChunk = sentence;
93
- } else {
94
- currentChunk += (currentChunk ? ". " : "") + sentence;
95
- }
96
- }
97
-
98
- if (currentChunk) {
99
- chunks.push(currentChunk);
100
- }
101
- }
102
- }
103
-
104
- return chunks;
105
- }
106
-
107
- /**
108
- * This demonstrates how to use the ZepClient to interact with a Zep API.
109
- */
110
- async function main() {
111
- const projectApiKey = process.env.ZEP_API_KEY;
112
-
113
- const file = "babbages_calculating_engine.txt";
114
- const maxChunkSize = 500;
115
- const collectionName = `babbage${faker.string.alphanumeric({ length: 8 })}`;
116
-
117
- console.log(`Creating collection ${collectionName}`);
118
-
119
- const client = new ZepClient({
120
- apiKey: projectApiKey,
121
- });
122
- await client.document.addCollection(collectionName, {
123
- description: "Babbage's Calculating Engine", // optional
124
- metadata: { qux: faker.string.sample() }, // optional
125
- });
126
-
127
- console.log(`Created collection ${collectionName}`);
128
-
129
- const chunks = readChunkFromFile(file, maxChunkSize);
130
-
131
- const documents: CreateDocumentRequest[] = chunks.map((chunk) => ({
132
- content: chunk,
133
- documentId: faker.system.fileName(), // optional document ID used in your system
134
- metadata: { foo: faker.string.sample(), bar: "qux" }, // optional metadata
135
- }));
136
-
137
- console.log(`Adding ${documents.length} documents to collection ${collectionName}`);
138
-
139
- const uuids = await client.document.addDocuments(collectionName, documents);
140
-
141
- console.log(`Added ${uuids.length} documents to collection ${collectionName}`);
142
-
143
- await checkEmbeddingStatus(client, collectionName);
144
-
145
- // Search for documents using text
146
- const query = "The celestial motions are nothing but a continual";
147
- const { results: searchResults } = await client.document.search(collectionName, {
148
- text: query,
149
- limit: 3,
150
- });
151
- console.log(`Found ${searchResults!.length} documents matching query '${query}'`);
152
- printResults(searchResults!);
153
-
154
- const mmrSearchResults = await client.document.search(collectionName, {
155
- text: query,
156
- searchType: "mmr",
157
- mmrLambda: 0.6,
158
- });
159
- console.log(`Found ${mmrSearchResults.results?.length} documents matching MMR query '${query}'`);
160
- printResults(mmrSearchResults.results!);
161
-
162
- // Search for documents using both text and metadata
163
- const metadataQuery = {
164
- where: { jsonpath: '$[*] ? (@.bar == "qux")' },
165
- };
166
-
167
- const { results: newSearchResults } = await client.document.search(collectionName, {
168
- text: query,
169
- metadata: metadataQuery,
170
- limit: 3,
171
- });
172
- console.log(`Found ${newSearchResults!.length} documents matching query '${query}' ${metadataQuery}`);
173
- printResults(newSearchResults!);
174
-
175
- // Search for non-existent documents will result in an empty array
176
- await client.document.search(collectionName, {
177
- metadata: {
178
- where: { jsonpath: '$[*] ? (@.this_key_does == "not exist")' },
179
- },
180
- limit: 3,
181
- });
182
-
183
- // Delete the collection
184
- console.log(`Deleting collection ${collectionName}`);
185
- await client.document.deleteCollection(collectionName);
186
- }
187
-
188
- main();
@@ -1,34 +0,0 @@
1
- import { ZepClient, zepFields } from "../../src";
2
- import { type ExtractedData } from "../../src/extractor";
3
-
4
- async function main() {
5
- const projectApiKey = process.env.ZEP_API_KEY;
6
- const sessionId = process.env.ZEP_SESSION_ID;
7
- if (!sessionId) {
8
- console.error("Please provide a session ID using the ZEP_SESSION_ID environment variable");
9
- return;
10
- }
11
-
12
- const client = new ZepClient({
13
- apiKey: projectApiKey,
14
- });
15
-
16
- const customerSchema = {
17
- shoeSize: zepFields.number("The Customer's shoe size"),
18
- budget: zepFields.number("The Customer's budget for shoe purchase"),
19
- favoriteBrand: zepFields.text("The Customer's favorite shoe brand. Just one brand, please!"),
20
- formattedPrice: zepFields.regex("The formatted price of the shoe", /\d+\.\d{2}/),
21
- };
22
-
23
- type Customer = ExtractedData<typeof customerSchema>;
24
-
25
- const result: Customer = await client.memory.extract(sessionId, customerSchema, {
26
- lastN: 20,
27
- validate: false,
28
- currentDateTime: new Date().toISOString(),
29
- });
30
-
31
- console.log("Data Extraction Result", result);
32
- }
33
-
34
- main();