@getzep/zep-cloud 0.0.1-rc.1 → 0.0.1-rc.2
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.
- package/package.json +1 -1
- package/.idea/aws.xml +0 -11
- package/.idea/codeStyles/Project.xml +0 -57
- package/.idea/codeStyles/codeStyleConfig.xml +0 -5
- package/.idea/golinter.xml +0 -6
- package/.idea/inspectionProfiles/Project_Default.xml +0 -6
- package/.idea/jsLinters/eslint.xml +0 -6
- package/.idea/misc.xml +0 -6
- package/.idea/modules.xml +0 -8
- package/.idea/prettier.xml +0 -7
- package/.idea/vcs.xml +0 -12
- package/.idea/zep-js.iml +0 -10
- package/dist/serialization/resources/memory/client/getSessionMessages.d.ts +0 -11
- package/dist/serialization/resources/memory/client/getSessionMessages.js +0 -32
- package/dist/serialization/resources/user/client/listOrdered.d.ts +0 -11
- package/dist/serialization/resources/user/client/listOrdered.js +0 -32
- package/esm/document_collection.d.ts +0 -96
- package/esm/document_collection.js +0 -304
- package/esm/document_manager.d.ts +0 -58
- package/esm/document_manager.js +0 -158
- package/esm/document_models.d.ts +0 -81
- package/esm/document_models.js +0 -64
- package/esm/errors.d.ts +0 -29
- package/esm/errors.js +0 -32
- package/esm/index.d.ts +0 -13
- package/esm/index.js +0 -12
- package/esm/interfaces.d.ts +0 -28
- package/esm/interfaces.js +0 -1
- package/esm/langchain/base_memory.d.ts +0 -58
- package/esm/langchain/base_memory.js +0 -87
- package/esm/langchain/index.d.ts +0 -3
- package/esm/langchain/index.js +0 -3
- package/esm/langchain/memory/chat_memory.d.ts +0 -38
- package/esm/langchain/memory/chat_memory.js +0 -49
- package/esm/langchain/memory/index.d.ts +0 -84
- package/esm/langchain/memory/index.js +0 -192
- package/esm/langchain/memory.d.ts +0 -79
- package/esm/langchain/memory.js +0 -205
- package/esm/langchain/message_history.d.ts +0 -39
- package/esm/langchain/message_history.js +0 -125
- package/esm/langchain/utils.d.ts +0 -12
- package/esm/langchain/utils.js +0 -37
- package/esm/langchain/vector_store.d.ts +0 -143
- package/esm/langchain/vector_store.js +0 -319
- package/esm/langchain/zep_message_placeholder.d.ts +0 -23
- package/esm/langchain/zep_message_placeholder.js +0 -73
- package/esm/memory_manager.d.ts +0 -112
- package/esm/memory_manager.js +0 -302
- package/esm/memory_models.d.ts +0 -184
- package/esm/memory_models.js +0 -141
- package/esm/message_manager.d.ts +0 -9
- package/esm/message_manager.js +0 -71
- package/esm/message_models.d.ts +0 -37
- package/esm/message_models.js +0 -49
- package/esm/user_manager.d.ts +0 -76
- package/esm/user_manager.js +0 -174
- package/esm/user_models.d.ts +0 -84
- package/esm/user_models.js +0 -44
- package/esm/utils.d.ts +0 -18
- package/esm/utils.js +0 -95
- package/esm/zep-client.d.ts +0 -41
- package/esm/zep-client.js +0 -104
- package/langchain/base_memory.d.ts +0 -58
- package/langchain/base_memory.js +0 -92
- package/langchain/memory/chat_memory.d.ts +0 -38
- package/langchain/memory/chat_memory.js +0 -53
- package/langchain/memory/index.d.ts +0 -84
- package/langchain/memory/index.js +0 -196
- package/langchain/memory.d.ts +0 -79
- package/langchain/memory.js +0 -212
- package/langchain/zep_message_placeholder.d.ts +0 -23
- package/langchain/zep_message_placeholder.js +0 -77
- package/serialization/resources/memory/client/getSessionMessages.d.ts +0 -11
- package/serialization/resources/memory/client/getSessionMessages.js +0 -32
- package/serialization/resources/user/client/listOrdered.d.ts +0 -11
- package/serialization/resources/user/client/listOrdered.js +0 -32
package/package.json
CHANGED
package/.idea/aws.xml
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
-
<project version="4">
|
|
3
|
-
<component name="accountSettings">
|
|
4
|
-
<option name="activeRegion" value="us-east-1" />
|
|
5
|
-
<option name="recentlyUsedRegions">
|
|
6
|
-
<list>
|
|
7
|
-
<option value="us-east-1" />
|
|
8
|
-
</list>
|
|
9
|
-
</option>
|
|
10
|
-
</component>
|
|
11
|
-
</project>
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
<component name="ProjectCodeStyleConfiguration">
|
|
2
|
-
<code_scheme name="Project" version="173">
|
|
3
|
-
<HTMLCodeStyleSettings>
|
|
4
|
-
<option name="HTML_SPACE_INSIDE_EMPTY_TAG" value="true" />
|
|
5
|
-
</HTMLCodeStyleSettings>
|
|
6
|
-
<JSCodeStyleSettings version="0">
|
|
7
|
-
<option name="FORCE_SEMICOLON_STYLE" value="true" />
|
|
8
|
-
<option name="SPACE_BEFORE_FUNCTION_LEFT_PARENTH" value="false" />
|
|
9
|
-
<option name="FORCE_QUOTE_STYlE" value="true" />
|
|
10
|
-
<option name="ENFORCE_TRAILING_COMMA" value="Remove" />
|
|
11
|
-
<option name="SPACES_WITHIN_OBJECT_LITERAL_BRACES" value="true" />
|
|
12
|
-
<option name="SPACES_WITHIN_IMPORTS" value="true" />
|
|
13
|
-
</JSCodeStyleSettings>
|
|
14
|
-
<TypeScriptCodeStyleSettings version="0">
|
|
15
|
-
<option name="FORCE_SEMICOLON_STYLE" value="true" />
|
|
16
|
-
<option name="SPACE_BEFORE_FUNCTION_LEFT_PARENTH" value="false" />
|
|
17
|
-
<option name="FORCE_QUOTE_STYlE" value="true" />
|
|
18
|
-
<option name="ENFORCE_TRAILING_COMMA" value="Remove" />
|
|
19
|
-
<option name="SPACES_WITHIN_OBJECT_LITERAL_BRACES" value="true" />
|
|
20
|
-
<option name="SPACES_WITHIN_IMPORTS" value="true" />
|
|
21
|
-
</TypeScriptCodeStyleSettings>
|
|
22
|
-
<VueCodeStyleSettings>
|
|
23
|
-
<option name="INTERPOLATION_NEW_LINE_AFTER_START_DELIMITER" value="false" />
|
|
24
|
-
<option name="INTERPOLATION_NEW_LINE_BEFORE_END_DELIMITER" value="false" />
|
|
25
|
-
</VueCodeStyleSettings>
|
|
26
|
-
<codeStyleSettings language="HTML">
|
|
27
|
-
<option name="SOFT_MARGINS" value="80" />
|
|
28
|
-
<indentOptions>
|
|
29
|
-
<option name="INDENT_SIZE" value="2" />
|
|
30
|
-
<option name="CONTINUATION_INDENT_SIZE" value="2" />
|
|
31
|
-
<option name="TAB_SIZE" value="2" />
|
|
32
|
-
</indentOptions>
|
|
33
|
-
</codeStyleSettings>
|
|
34
|
-
<codeStyleSettings language="JavaScript">
|
|
35
|
-
<option name="SOFT_MARGINS" value="80" />
|
|
36
|
-
<indentOptions>
|
|
37
|
-
<option name="INDENT_SIZE" value="2" />
|
|
38
|
-
<option name="CONTINUATION_INDENT_SIZE" value="2" />
|
|
39
|
-
<option name="TAB_SIZE" value="2" />
|
|
40
|
-
</indentOptions>
|
|
41
|
-
</codeStyleSettings>
|
|
42
|
-
<codeStyleSettings language="TypeScript">
|
|
43
|
-
<option name="SOFT_MARGINS" value="80" />
|
|
44
|
-
<indentOptions>
|
|
45
|
-
<option name="INDENT_SIZE" value="2" />
|
|
46
|
-
<option name="CONTINUATION_INDENT_SIZE" value="2" />
|
|
47
|
-
<option name="TAB_SIZE" value="2" />
|
|
48
|
-
</indentOptions>
|
|
49
|
-
</codeStyleSettings>
|
|
50
|
-
<codeStyleSettings language="Vue">
|
|
51
|
-
<option name="SOFT_MARGINS" value="80" />
|
|
52
|
-
<indentOptions>
|
|
53
|
-
<option name="CONTINUATION_INDENT_SIZE" value="2" />
|
|
54
|
-
</indentOptions>
|
|
55
|
-
</codeStyleSettings>
|
|
56
|
-
</code_scheme>
|
|
57
|
-
</component>
|
package/.idea/golinter.xml
DELETED
package/.idea/misc.xml
DELETED
package/.idea/modules.xml
DELETED
package/.idea/prettier.xml
DELETED
package/.idea/vcs.xml
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
-
<project version="4">
|
|
3
|
-
<component name="CommitMessageInspectionProfile">
|
|
4
|
-
<profile version="1.0">
|
|
5
|
-
<inspection_tool class="CommitFormat" enabled="true" level="WARNING" enabled_by_default="true" />
|
|
6
|
-
<inspection_tool class="CommitNamingConvention" enabled="true" level="WARNING" enabled_by_default="true" />
|
|
7
|
-
</profile>
|
|
8
|
-
</component>
|
|
9
|
-
<component name="VcsDirectoryMappings">
|
|
10
|
-
<mapping directory="" vcs="Git" />
|
|
11
|
-
</component>
|
|
12
|
-
</project>
|
package/.idea/zep-js.iml
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
-
<module type="JAVA_MODULE" version="4">
|
|
3
|
-
<component name="Go" enabled="true" />
|
|
4
|
-
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
|
5
|
-
<exclude-output />
|
|
6
|
-
<content url="file://$MODULE_DIR$" />
|
|
7
|
-
<orderEntry type="inheritedJdk" />
|
|
8
|
-
<orderEntry type="sourceFolder" forTests="false" />
|
|
9
|
-
</component>
|
|
10
|
-
</module>
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* This file was auto-generated by Fern from our API Definition.
|
|
3
|
-
*/
|
|
4
|
-
import * as serializers from "../../..";
|
|
5
|
-
import * as Zep from "../../../../api";
|
|
6
|
-
import * as core from "../../../../core";
|
|
7
|
-
import { Message } from "../../../types/Message";
|
|
8
|
-
export declare const Response: core.serialization.Schema<serializers.memory.getSessionMessages.Response.Raw, Zep.Message[]>;
|
|
9
|
-
export declare namespace Response {
|
|
10
|
-
type Raw = Message.Raw[];
|
|
11
|
-
}
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* This file was auto-generated by Fern from our API Definition.
|
|
4
|
-
*/
|
|
5
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
6
|
-
if (k2 === undefined) k2 = k;
|
|
7
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
8
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
9
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
10
|
-
}
|
|
11
|
-
Object.defineProperty(o, k2, desc);
|
|
12
|
-
}) : (function(o, m, k, k2) {
|
|
13
|
-
if (k2 === undefined) k2 = k;
|
|
14
|
-
o[k2] = m[k];
|
|
15
|
-
}));
|
|
16
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
17
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
18
|
-
}) : function(o, v) {
|
|
19
|
-
o["default"] = v;
|
|
20
|
-
});
|
|
21
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
22
|
-
if (mod && mod.__esModule) return mod;
|
|
23
|
-
var result = {};
|
|
24
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
25
|
-
__setModuleDefault(result, mod);
|
|
26
|
-
return result;
|
|
27
|
-
};
|
|
28
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
exports.Response = void 0;
|
|
30
|
-
const core = __importStar(require("../../../../core"));
|
|
31
|
-
const Message_1 = require("../../../types/Message");
|
|
32
|
-
exports.Response = core.serialization.list(Message_1.Message);
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* This file was auto-generated by Fern from our API Definition.
|
|
3
|
-
*/
|
|
4
|
-
import * as serializers from "../../..";
|
|
5
|
-
import * as Zep from "../../../../api";
|
|
6
|
-
import * as core from "../../../../core";
|
|
7
|
-
import { User } from "../../../types/User";
|
|
8
|
-
export declare const Response: core.serialization.Schema<serializers.user.listOrdered.Response.Raw, Zep.User[]>;
|
|
9
|
-
export declare namespace Response {
|
|
10
|
-
type Raw = User.Raw[];
|
|
11
|
-
}
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* This file was auto-generated by Fern from our API Definition.
|
|
4
|
-
*/
|
|
5
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
6
|
-
if (k2 === undefined) k2 = k;
|
|
7
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
8
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
9
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
10
|
-
}
|
|
11
|
-
Object.defineProperty(o, k2, desc);
|
|
12
|
-
}) : (function(o, m, k, k2) {
|
|
13
|
-
if (k2 === undefined) k2 = k;
|
|
14
|
-
o[k2] = m[k];
|
|
15
|
-
}));
|
|
16
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
17
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
18
|
-
}) : function(o, v) {
|
|
19
|
-
o["default"] = v;
|
|
20
|
-
});
|
|
21
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
22
|
-
if (mod && mod.__esModule) return mod;
|
|
23
|
-
var result = {};
|
|
24
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
25
|
-
__setModuleDefault(result, mod);
|
|
26
|
-
return result;
|
|
27
|
-
};
|
|
28
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
exports.Response = void 0;
|
|
30
|
-
const core = __importStar(require("../../../../core"));
|
|
31
|
-
const User_1 = require("../../../types/User");
|
|
32
|
-
exports.Response = core.serialization.list(User_1.User);
|
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
import { DocumentCollectionModel, IDocument, IDocumentCollectionModel } from "./document_models";
|
|
2
|
-
import { ISearchQuery, IUpdateDocumentParams, IZepClient } from "./interfaces";
|
|
3
|
-
/**
|
|
4
|
-
* DocumentCollection extends DocumentCollectionModel.
|
|
5
|
-
* It provides methods to interact with a Zep document collection.
|
|
6
|
-
*/
|
|
7
|
-
export default class DocumentCollection extends DocumentCollectionModel {
|
|
8
|
-
private client;
|
|
9
|
-
/**
|
|
10
|
-
* Constructs a new DocumentCollection instance.
|
|
11
|
-
* @param {IZepClient} client - The Zep client instance.
|
|
12
|
-
* @param {IDocumentCollectionModel} params - The parameters for the document collection.
|
|
13
|
-
*/
|
|
14
|
-
constructor(client: IZepClient, params: IDocumentCollectionModel);
|
|
15
|
-
/**
|
|
16
|
-
* Returns the status of the document collection.
|
|
17
|
-
* @returns {string} The status of the document collection.
|
|
18
|
-
* "ready" if all documents are embedded, "pending" otherwise.
|
|
19
|
-
*/
|
|
20
|
-
get status(): string;
|
|
21
|
-
/**
|
|
22
|
-
* Adds documents to the collection.
|
|
23
|
-
* @param {IDocument[]} documents - The documents to add.
|
|
24
|
-
* @returns {Promise<string[]>} A promise that resolves to an array of document UUIDs.
|
|
25
|
-
* @throws {Error} If the collection name is not provided or no documents are provided.
|
|
26
|
-
* @throws {APIError} If the request fails.
|
|
27
|
-
*/
|
|
28
|
-
addDocuments(documents: IDocument[]): Promise<string[]>;
|
|
29
|
-
/**
|
|
30
|
-
* Updates a document in the collection.
|
|
31
|
-
* @param {IUpdateDocumentParams} params - The parameters to update the document.
|
|
32
|
-
* @returns {Promise<void>} A promise that resolves when the document is updated.
|
|
33
|
-
* @throws {Error} If the collection name is not provided or the document does not have a uuid.
|
|
34
|
-
* @throws {APIError} If the request fails.
|
|
35
|
-
* @throws {NotFoundError} If the request no document is found for the given uuid.
|
|
36
|
-
*/
|
|
37
|
-
updateDocument({ uuid, documentId, metadata, }: IUpdateDocumentParams): Promise<void>;
|
|
38
|
-
/**
|
|
39
|
-
* Deletes a document from the collection.
|
|
40
|
-
* @param {string} uuid - The uuid of the document to delete.
|
|
41
|
-
* @returns {Promise<void>} A promise that resolves when the document is deleted.
|
|
42
|
-
* @throws {Error} If the collection name is not provided or the document does not have a uuid.
|
|
43
|
-
* @throws {APIError} If the request fails.
|
|
44
|
-
* @throws {NotFoundError} If the request no document is found for the given uuid.
|
|
45
|
-
*/
|
|
46
|
-
deleteDocument(uuid: string): Promise<void>;
|
|
47
|
-
/**
|
|
48
|
-
* Gets a document from the collection.
|
|
49
|
-
* @param {string} uuid - The uuid of the document to get.
|
|
50
|
-
* @returns {Promise<IDocument>} A promise that resolves to the document.
|
|
51
|
-
* @throws {Error} If the collection name is not provided or the document does not have a uuid.
|
|
52
|
-
* @throws {APIError} If the request fails.
|
|
53
|
-
* @throws {NotFoundError} If the request no document is found for the given uuid.
|
|
54
|
-
*/
|
|
55
|
-
getDocument(uuid: string): Promise<IDocument>;
|
|
56
|
-
/**
|
|
57
|
-
* Gets multiple documents from the collection.
|
|
58
|
-
* @param {string[]} uuids - The uuids of the documents to get.
|
|
59
|
-
* @returns {Promise<IDocument[]>} A promise that resolves to an array of documents.
|
|
60
|
-
* @throws {Error} If any of the documents do not match the expected format.
|
|
61
|
-
* @throws {Error} If the collection name is not provided or no uuids are provided.
|
|
62
|
-
* @throws {APIError} If the request fails.
|
|
63
|
-
*/
|
|
64
|
-
getDocuments(uuids: string[]): Promise<IDocument[]>;
|
|
65
|
-
/**
|
|
66
|
-
* Searches the collection and returns the results and the query vector.
|
|
67
|
-
* @param {ISearchQuery} query - The search query.
|
|
68
|
-
* @param {number} [limit] - The maximum number of results to return.
|
|
69
|
-
* @returns {Promise<[IDocument[], Float32Array]>}
|
|
70
|
-
* A promise that resolves to an array of documents and the query vector.
|
|
71
|
-
* @throws {Error} If the collection name is not provided or
|
|
72
|
-
* the search query does not have at least one of text, embedding, or metadata.
|
|
73
|
-
* @throws {APIError} If the request fails.
|
|
74
|
-
*/
|
|
75
|
-
searchReturnQueryVector(query: ISearchQuery, limit?: number): Promise<[IDocument[], Float32Array]>;
|
|
76
|
-
/**
|
|
77
|
-
* Searches the collection.
|
|
78
|
-
* @param {ISearchQuery} query - The search query.
|
|
79
|
-
* @param {number} [limit] - The maximum number of results to return.
|
|
80
|
-
* @returns {Promise<IDocument[]>} A promise that resolves to an array of documents.
|
|
81
|
-
* @throws {Error} If the collection name is not provided or
|
|
82
|
-
* the search query does not have at least one of text, embedding, or metadata.
|
|
83
|
-
* @throws {APIError} If the request fails.
|
|
84
|
-
*/
|
|
85
|
-
search(query: ISearchQuery, limit?: number): Promise<IDocument[]>;
|
|
86
|
-
/**
|
|
87
|
-
* Creates an index for the collection.
|
|
88
|
-
* @param {boolean} [force=false] - Whether to force index creation even if
|
|
89
|
-
* there are less than MIN_DOCS_TO_INDEX documents.
|
|
90
|
-
* @returns {Promise<void>} A promise that resolves when the index is created.
|
|
91
|
-
* @throws {Error} If the collection name is not provided or the collection
|
|
92
|
-
* has less than MIN_DOCS_TO_INDEX documents and force is not true.
|
|
93
|
-
* @throws {APIError} If the request fails.
|
|
94
|
-
*/
|
|
95
|
-
createIndex(force?: boolean): Promise<void>;
|
|
96
|
-
}
|
|
@@ -1,304 +0,0 @@
|
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
|
-
import { PromisePool } from "@supercharge/promise-pool";
|
|
11
|
-
import { docsToDocsWithFloatArray, docsWithFloatArrayToDocs, DocumentCollectionModel, isGetIDocument, } from "./document_models";
|
|
12
|
-
import { handleRequest, isFloat } from "./utils";
|
|
13
|
-
import { APIError } from "./errors";
|
|
14
|
-
const MIN_DOCS_TO_INDEX = 10000;
|
|
15
|
-
const DEFAULT_BATCH_SIZE = 500;
|
|
16
|
-
const MAX_CONCURRENT_BATCHES = 5;
|
|
17
|
-
const LARGE_BATCH_WARNING_LIMIT = 1000;
|
|
18
|
-
const LARGE_BATCH_WARNING = `Batch size is greater than ${LARGE_BATCH_WARNING_LIMIT}.
|
|
19
|
-
This may result in slow performance or out-of-memory failures.`;
|
|
20
|
-
/**
|
|
21
|
-
* DocumentCollection extends DocumentCollectionModel.
|
|
22
|
-
* It provides methods to interact with a Zep document collection.
|
|
23
|
-
*/
|
|
24
|
-
export default class DocumentCollection extends DocumentCollectionModel {
|
|
25
|
-
/**
|
|
26
|
-
* Constructs a new DocumentCollection instance.
|
|
27
|
-
* @param {IZepClient} client - The Zep client instance.
|
|
28
|
-
* @param {IDocumentCollectionModel} params - The parameters for the document collection.
|
|
29
|
-
*/
|
|
30
|
-
constructor(client, params) {
|
|
31
|
-
super(params);
|
|
32
|
-
this.client = client;
|
|
33
|
-
}
|
|
34
|
-
/**
|
|
35
|
-
* Returns the status of the document collection.
|
|
36
|
-
* @returns {string} The status of the document collection.
|
|
37
|
-
* "ready" if all documents are embedded, "pending" otherwise.
|
|
38
|
-
*/
|
|
39
|
-
get status() {
|
|
40
|
-
if (this.document_count &&
|
|
41
|
-
this.document_embedded_count === this.document_count) {
|
|
42
|
-
return "ready";
|
|
43
|
-
}
|
|
44
|
-
return "pending";
|
|
45
|
-
}
|
|
46
|
-
/**
|
|
47
|
-
* Adds documents to the collection.
|
|
48
|
-
* @param {IDocument[]} documents - The documents to add.
|
|
49
|
-
* @returns {Promise<string[]>} A promise that resolves to an array of document UUIDs.
|
|
50
|
-
* @throws {Error} If the collection name is not provided or no documents are provided.
|
|
51
|
-
* @throws {APIError} If the request fails.
|
|
52
|
-
*/
|
|
53
|
-
addDocuments(documents) {
|
|
54
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
55
|
-
if (this.name.length === 0) {
|
|
56
|
-
throw new Error("Collection name must be provided");
|
|
57
|
-
}
|
|
58
|
-
if (documents.length === 0) {
|
|
59
|
-
throw new Error("No documents provided");
|
|
60
|
-
}
|
|
61
|
-
if (documents.length > LARGE_BATCH_WARNING_LIMIT) {
|
|
62
|
-
console.warn(LARGE_BATCH_WARNING);
|
|
63
|
-
}
|
|
64
|
-
// 1. Split the documents into batches of DEFAULT_BATCH_SIZE
|
|
65
|
-
const batches = [];
|
|
66
|
-
for (let i = 0; i < documents.length; i += DEFAULT_BATCH_SIZE) {
|
|
67
|
-
batches.push(documents.slice(i, i + DEFAULT_BATCH_SIZE));
|
|
68
|
-
}
|
|
69
|
-
// 2. Create a function that will take a batch of documents and
|
|
70
|
-
// return a promise that resolves when the batch is uploaded.
|
|
71
|
-
const uploadBatch = (batch) => __awaiter(this, void 0, void 0, function* () {
|
|
72
|
-
const body = JSON.stringify(docsWithFloatArrayToDocs(batch));
|
|
73
|
-
const url = this.client.getFullUrl(`/collections/${this.name}/documents`);
|
|
74
|
-
const response = yield handleRequest(fetch(url, {
|
|
75
|
-
method: "POST",
|
|
76
|
-
headers: Object.assign(Object.assign({}, this.client.headers), { "Content-Type": "application/json" }),
|
|
77
|
-
body,
|
|
78
|
-
}));
|
|
79
|
-
return response.json();
|
|
80
|
-
});
|
|
81
|
-
// 3. Upload the batches in parallel
|
|
82
|
-
// limit the number of concurrent batches to MAX_CONCURRENT_BATCHES
|
|
83
|
-
const { results } = yield PromisePool.for(batches)
|
|
84
|
-
.withConcurrency(MAX_CONCURRENT_BATCHES)
|
|
85
|
-
.process(uploadBatch);
|
|
86
|
-
// Flatten the results array
|
|
87
|
-
return results.flat();
|
|
88
|
-
});
|
|
89
|
-
}
|
|
90
|
-
/**
|
|
91
|
-
* Updates a document in the collection.
|
|
92
|
-
* @param {IUpdateDocumentParams} params - The parameters to update the document.
|
|
93
|
-
* @returns {Promise<void>} A promise that resolves when the document is updated.
|
|
94
|
-
* @throws {Error} If the collection name is not provided or the document does not have a uuid.
|
|
95
|
-
* @throws {APIError} If the request fails.
|
|
96
|
-
* @throws {NotFoundError} If the request no document is found for the given uuid.
|
|
97
|
-
*/
|
|
98
|
-
updateDocument({ uuid, documentId, metadata, }) {
|
|
99
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
100
|
-
if (this.name.length === 0) {
|
|
101
|
-
throw new Error("Collection name must be provided");
|
|
102
|
-
}
|
|
103
|
-
if (!uuid) {
|
|
104
|
-
throw new Error("Document must have a uuid");
|
|
105
|
-
}
|
|
106
|
-
const url = this.client.getFullUrl(`/collections/${this.name}/documents/${uuid}`);
|
|
107
|
-
yield handleRequest(fetch(url, {
|
|
108
|
-
method: "PATCH",
|
|
109
|
-
headers: Object.assign(Object.assign({}, this.client.headers), { "Content-Type": "application/json" }),
|
|
110
|
-
body: JSON.stringify({
|
|
111
|
-
uuid,
|
|
112
|
-
document_id: documentId,
|
|
113
|
-
metadata,
|
|
114
|
-
}),
|
|
115
|
-
}));
|
|
116
|
-
});
|
|
117
|
-
}
|
|
118
|
-
/**
|
|
119
|
-
* Deletes a document from the collection.
|
|
120
|
-
* @param {string} uuid - The uuid of the document to delete.
|
|
121
|
-
* @returns {Promise<void>} A promise that resolves when the document is deleted.
|
|
122
|
-
* @throws {Error} If the collection name is not provided or the document does not have a uuid.
|
|
123
|
-
* @throws {APIError} If the request fails.
|
|
124
|
-
* @throws {NotFoundError} If the request no document is found for the given uuid.
|
|
125
|
-
*/
|
|
126
|
-
deleteDocument(uuid) {
|
|
127
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
128
|
-
if (this.name.length === 0) {
|
|
129
|
-
throw new Error("Collection name must be provided");
|
|
130
|
-
}
|
|
131
|
-
if (uuid.length === 0) {
|
|
132
|
-
throw new Error("Document must have a uuid");
|
|
133
|
-
}
|
|
134
|
-
const url = this.client.getFullUrl(`/collections/${this.name}/documents/uuid/${uuid}`);
|
|
135
|
-
yield handleRequest(fetch(url, {
|
|
136
|
-
method: "DELETE",
|
|
137
|
-
headers: this.client.headers,
|
|
138
|
-
}));
|
|
139
|
-
});
|
|
140
|
-
}
|
|
141
|
-
/**
|
|
142
|
-
* Gets a document from the collection.
|
|
143
|
-
* @param {string} uuid - The uuid of the document to get.
|
|
144
|
-
* @returns {Promise<IDocument>} A promise that resolves to the document.
|
|
145
|
-
* @throws {Error} If the collection name is not provided or the document does not have a uuid.
|
|
146
|
-
* @throws {APIError} If the request fails.
|
|
147
|
-
* @throws {NotFoundError} If the request no document is found for the given uuid.
|
|
148
|
-
*/
|
|
149
|
-
getDocument(uuid) {
|
|
150
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
151
|
-
if (this.name.length === 0) {
|
|
152
|
-
throw new Error("Collection name must be provided");
|
|
153
|
-
}
|
|
154
|
-
if (uuid.length === 0) {
|
|
155
|
-
throw new Error("Document must have a uuid");
|
|
156
|
-
}
|
|
157
|
-
const url = this.client.getFullUrl(`/collections/${this.name}/documents/${uuid}`);
|
|
158
|
-
const response = yield handleRequest(fetch(url, {
|
|
159
|
-
headers: this.client.headers,
|
|
160
|
-
}));
|
|
161
|
-
const document = yield response.json();
|
|
162
|
-
if (!isGetIDocument(document)) {
|
|
163
|
-
throw new APIError("Unexpected document response from server");
|
|
164
|
-
}
|
|
165
|
-
// embedding object or array to Float32Array
|
|
166
|
-
if (document.embedding) {
|
|
167
|
-
document.embedding = new Float32Array(document.embedding);
|
|
168
|
-
}
|
|
169
|
-
return document;
|
|
170
|
-
});
|
|
171
|
-
}
|
|
172
|
-
/**
|
|
173
|
-
* Gets multiple documents from the collection.
|
|
174
|
-
* @param {string[]} uuids - The uuids of the documents to get.
|
|
175
|
-
* @returns {Promise<IDocument[]>} A promise that resolves to an array of documents.
|
|
176
|
-
* @throws {Error} If any of the documents do not match the expected format.
|
|
177
|
-
* @throws {Error} If the collection name is not provided or no uuids are provided.
|
|
178
|
-
* @throws {APIError} If the request fails.
|
|
179
|
-
*/
|
|
180
|
-
getDocuments(uuids) {
|
|
181
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
182
|
-
if (uuids.length === 0) {
|
|
183
|
-
throw new Error("No uuids provided");
|
|
184
|
-
}
|
|
185
|
-
if (this.name.length === 0) {
|
|
186
|
-
throw new Error("Collection name must be provided");
|
|
187
|
-
}
|
|
188
|
-
if (uuids.length > LARGE_BATCH_WARNING_LIMIT) {
|
|
189
|
-
console.warn(LARGE_BATCH_WARNING);
|
|
190
|
-
}
|
|
191
|
-
const url = this.client.getFullUrl(`/collections/${this.name}/documents/list/get`);
|
|
192
|
-
const response = yield handleRequest(fetch(url, {
|
|
193
|
-
method: "POST",
|
|
194
|
-
headers: Object.assign(Object.assign({}, this.client.headers), { "Content-Type": "application/json" }),
|
|
195
|
-
body: JSON.stringify({ uuids }),
|
|
196
|
-
}));
|
|
197
|
-
const documents = yield response.json();
|
|
198
|
-
if (!Array.isArray(documents)) {
|
|
199
|
-
throw new APIError("Unexpected document response from server");
|
|
200
|
-
}
|
|
201
|
-
if (documents.map((d) => isGetIDocument(d)).includes(false)) {
|
|
202
|
-
throw new APIError("Unexpected document response from server");
|
|
203
|
-
}
|
|
204
|
-
// embedding object or array to Float32Array
|
|
205
|
-
return docsToDocsWithFloatArray(documents);
|
|
206
|
-
});
|
|
207
|
-
}
|
|
208
|
-
/**
|
|
209
|
-
* Searches the collection and returns the results and the query vector.
|
|
210
|
-
* @param {ISearchQuery} query - The search query.
|
|
211
|
-
* @param {number} [limit] - The maximum number of results to return.
|
|
212
|
-
* @returns {Promise<[IDocument[], Float32Array]>}
|
|
213
|
-
* A promise that resolves to an array of documents and the query vector.
|
|
214
|
-
* @throws {Error} If the collection name is not provided or
|
|
215
|
-
* the search query does not have at least one of text, embedding, or metadata.
|
|
216
|
-
* @throws {APIError} If the request fails.
|
|
217
|
-
*/
|
|
218
|
-
searchReturnQueryVector(query, limit) {
|
|
219
|
-
var _a, _b, _c;
|
|
220
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
221
|
-
if (this.name.length === 0) {
|
|
222
|
-
throw new Error("Collection name must be provided");
|
|
223
|
-
}
|
|
224
|
-
if (((_a = query.text) === null || _a === void 0 ? void 0 : _a.length) === 0 &&
|
|
225
|
-
((_b = query.embedding) === null || _b === void 0 ? void 0 : _b.length) === 0 &&
|
|
226
|
-
((_c = query.metadata) === null || _c === void 0 ? void 0 : _c.length) === 0) {
|
|
227
|
-
throw new Error("Search query must have at least one of text, embedding, or metadata");
|
|
228
|
-
}
|
|
229
|
-
const q = Object.assign(Object.assign({}, query), { search_type: query.searchType, mmr_lambda: query.mmrLambda, embedding: query.embedding ? Array.from(query.embedding) : undefined });
|
|
230
|
-
const payload = JSON.stringify(Object.fromEntries(Object.entries(q).filter(([k, v]) => v !== undefined && k !== "mmrLambda" && k !== "searchType")));
|
|
231
|
-
const limitParam = limit ? `?limit=${limit}` : "";
|
|
232
|
-
const url = this.client.getFullUrl(`/collections/${this.name}/search`) +
|
|
233
|
-
limitParam;
|
|
234
|
-
const response = yield handleRequest(fetch(url, {
|
|
235
|
-
method: "POST",
|
|
236
|
-
headers: Object.assign(Object.assign({}, this.client.headers), { "Content-Type": "application/json" }),
|
|
237
|
-
body: payload,
|
|
238
|
-
}));
|
|
239
|
-
const results = yield response.json();
|
|
240
|
-
const { results: documents, query_vector: queryVector } = results;
|
|
241
|
-
if (documents.length === 0) {
|
|
242
|
-
return [[], new Float32Array()];
|
|
243
|
-
}
|
|
244
|
-
if (!Array.isArray(documents)) {
|
|
245
|
-
throw new APIError("Unexpected document response from server");
|
|
246
|
-
}
|
|
247
|
-
if (documents.map((d) => isGetIDocument(d)).includes(false)) {
|
|
248
|
-
throw new APIError("Unexpected document response from server");
|
|
249
|
-
}
|
|
250
|
-
if (!Array.isArray(queryVector)) {
|
|
251
|
-
throw new APIError("Unexpected vector response from server");
|
|
252
|
-
}
|
|
253
|
-
if (queryVector.map((v) => isFloat(v)).includes(false)) {
|
|
254
|
-
throw new APIError("Unexpected vector response from server");
|
|
255
|
-
}
|
|
256
|
-
return [
|
|
257
|
-
docsToDocsWithFloatArray(documents),
|
|
258
|
-
new Float32Array(queryVector),
|
|
259
|
-
];
|
|
260
|
-
});
|
|
261
|
-
}
|
|
262
|
-
/**
|
|
263
|
-
* Searches the collection.
|
|
264
|
-
* @param {ISearchQuery} query - The search query.
|
|
265
|
-
* @param {number} [limit] - The maximum number of results to return.
|
|
266
|
-
* @returns {Promise<IDocument[]>} A promise that resolves to an array of documents.
|
|
267
|
-
* @throws {Error} If the collection name is not provided or
|
|
268
|
-
* the search query does not have at least one of text, embedding, or metadata.
|
|
269
|
-
* @throws {APIError} If the request fails.
|
|
270
|
-
*/
|
|
271
|
-
search(query, limit) {
|
|
272
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
273
|
-
const [results] = yield this.searchReturnQueryVector(query, limit);
|
|
274
|
-
return results;
|
|
275
|
-
});
|
|
276
|
-
}
|
|
277
|
-
/**
|
|
278
|
-
* Creates an index for the collection.
|
|
279
|
-
* @param {boolean} [force=false] - Whether to force index creation even if
|
|
280
|
-
* there are less than MIN_DOCS_TO_INDEX documents.
|
|
281
|
-
* @returns {Promise<void>} A promise that resolves when the index is created.
|
|
282
|
-
* @throws {Error} If the collection name is not provided or the collection
|
|
283
|
-
* has less than MIN_DOCS_TO_INDEX documents and force is not true.
|
|
284
|
-
* @throws {APIError} If the request fails.
|
|
285
|
-
*/
|
|
286
|
-
createIndex(force) {
|
|
287
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
288
|
-
const forceParam = force ? `?force=${force}` : "";
|
|
289
|
-
if (this.name.length === 0) {
|
|
290
|
-
throw new Error("Collection name must be provided");
|
|
291
|
-
}
|
|
292
|
-
if (!force &&
|
|
293
|
-
(this === null || this === void 0 ? void 0 : this.document_count) &&
|
|
294
|
-
(this === null || this === void 0 ? void 0 : this.document_count) < MIN_DOCS_TO_INDEX) {
|
|
295
|
-
throw new Error(`Collection must have at least ${MIN_DOCS_TO_INDEX} documents to index. Use force=true to override.`);
|
|
296
|
-
}
|
|
297
|
-
const url = this.client.getFullUrl(`/collections/${this.name}/index/create`);
|
|
298
|
-
yield handleRequest(fetch(url + forceParam, {
|
|
299
|
-
method: "POST",
|
|
300
|
-
headers: Object.assign(Object.assign({}, this.client.headers), { "Content-Type": "application/json" }),
|
|
301
|
-
}));
|
|
302
|
-
});
|
|
303
|
-
}
|
|
304
|
-
}
|