@agentskit/memory 0.7.0 → 0.8.1
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/dist/index.cjs +164 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +52 -1
- package/dist/index.d.ts +52 -1
- package/dist/index.js +162 -1
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -265,6 +265,57 @@ interface SupabaseVectorStoreConfig {
|
|
|
265
265
|
*/
|
|
266
266
|
declare function supabaseVectorStore(config: SupabaseVectorStoreConfig): VectorMemory;
|
|
267
267
|
|
|
268
|
+
interface WeaviateConfig {
|
|
269
|
+
/** Cluster URL, e.g. `https://my-cluster.weaviate.network`. */
|
|
270
|
+
url: string;
|
|
271
|
+
/** Optional API key (Weaviate Cloud Services). */
|
|
272
|
+
apiKey?: string;
|
|
273
|
+
/** Class name in the Weaviate schema. */
|
|
274
|
+
className: string;
|
|
275
|
+
topK?: number;
|
|
276
|
+
fetch?: typeof globalThis.fetch;
|
|
277
|
+
}
|
|
278
|
+
declare function weaviateVectorStore(config: WeaviateConfig): VectorMemory;
|
|
279
|
+
|
|
280
|
+
interface MilvusConfig {
|
|
281
|
+
/** Milvus REST endpoint, e.g. `https://in03-xxx.api.gcp-us-west1.zillizcloud.com`. */
|
|
282
|
+
url: string;
|
|
283
|
+
/** API key / Zilliz Cloud token (Bearer). */
|
|
284
|
+
token?: string;
|
|
285
|
+
collection: string;
|
|
286
|
+
/** Vector field name in the schema. Default `vector`. */
|
|
287
|
+
vectorField?: string;
|
|
288
|
+
topK?: number;
|
|
289
|
+
fetch?: typeof globalThis.fetch;
|
|
290
|
+
}
|
|
291
|
+
declare function milvusVectorStore(config: MilvusConfig): VectorMemory;
|
|
292
|
+
|
|
293
|
+
/**
|
|
294
|
+
* MongoDB Atlas Vector Search adapter. Caller injects a typed collection
|
|
295
|
+
* shape (drop-in for the official `mongodb` driver's `Collection` type) so
|
|
296
|
+
* we don't bundle a driver. Atlas' \`$vectorSearch\` aggregation runs
|
|
297
|
+
* server-side; we just translate \`store\` / \`search\` / \`delete\` to
|
|
298
|
+
* insertMany + aggregate + deleteMany.
|
|
299
|
+
*/
|
|
300
|
+
interface MongoCollectionLike {
|
|
301
|
+
insertMany(docs: Array<Record<string, unknown>>, options?: unknown): Promise<unknown>;
|
|
302
|
+
deleteMany(filter: Record<string, unknown>): Promise<unknown>;
|
|
303
|
+
aggregate<T = Record<string, unknown>>(pipeline: Array<Record<string, unknown>>): {
|
|
304
|
+
toArray(): Promise<T[]>;
|
|
305
|
+
};
|
|
306
|
+
}
|
|
307
|
+
interface MongoAtlasVectorConfig {
|
|
308
|
+
collection: MongoCollectionLike;
|
|
309
|
+
/** Atlas Search index name on the embedding field. */
|
|
310
|
+
indexName: string;
|
|
311
|
+
/** Field that holds the embedding vector. Default `embedding`. */
|
|
312
|
+
vectorField?: string;
|
|
313
|
+
/** numCandidates for $vectorSearch. Default `topK * 10`. */
|
|
314
|
+
numCandidates?: number;
|
|
315
|
+
topK?: number;
|
|
316
|
+
}
|
|
317
|
+
declare function mongoAtlasVectorStore(config: MongoAtlasVectorConfig): VectorMemory;
|
|
318
|
+
|
|
268
319
|
/**
|
|
269
320
|
* Evaluate a `VectorFilter` against a metadata record. Used by in-memory /
|
|
270
321
|
* file-backed vector stores. Backends with native filter languages (pgvector,
|
|
@@ -361,4 +412,4 @@ interface HierarchicalMemory extends ChatMemory {
|
|
|
361
412
|
*/
|
|
362
413
|
declare function createHierarchicalMemory(options: HierarchicalMemoryOptions): HierarchicalMemory;
|
|
363
414
|
|
|
364
|
-
export { type ChromaConfig, type EncryptedEnvelope, type EncryptedMemoryOptions, type FileVectorMemoryConfig, type GraphEdge, type GraphMemory, type GraphNode, type GraphQuery, type HierarchicalMemory, type HierarchicalMemoryOptions, type HierarchicalRecall, type PersonalizationProfile, type PersonalizationStore, type PgVectorConfig, type PgVectorRunner, type PineconeConfig, type QdrantConfig, type RedisChatMemoryConfig, type RedisClientAdapter, type RedisConnectionConfig, type RedisVectorMemoryConfig, type SqliteChatMemoryConfig, type SupabaseVectorStoreConfig, type TursoChatMemoryConfig, type UpstashVectorConfig, type VectorStore, type VectorStoreDocument, type VectorStoreResult, chroma, createEncryptedMemory, createHierarchicalMemory, createInMemoryGraph, createInMemoryPersonalization, fileChatMemory, fileVectorMemory, matchesFilter, pgvector, pinecone, qdrant, redisChatMemory, redisVectorMemory, renderProfileContext, sqliteChatMemory, supabaseVectorStore, tursoChatMemory, upstashVector };
|
|
415
|
+
export { type ChromaConfig, type EncryptedEnvelope, type EncryptedMemoryOptions, type FileVectorMemoryConfig, type GraphEdge, type GraphMemory, type GraphNode, type GraphQuery, type HierarchicalMemory, type HierarchicalMemoryOptions, type HierarchicalRecall, type MilvusConfig, type MongoAtlasVectorConfig, type MongoCollectionLike, type PersonalizationProfile, type PersonalizationStore, type PgVectorConfig, type PgVectorRunner, type PineconeConfig, type QdrantConfig, type RedisChatMemoryConfig, type RedisClientAdapter, type RedisConnectionConfig, type RedisVectorMemoryConfig, type SqliteChatMemoryConfig, type SupabaseVectorStoreConfig, type TursoChatMemoryConfig, type UpstashVectorConfig, type VectorStore, type VectorStoreDocument, type VectorStoreResult, type WeaviateConfig, chroma, createEncryptedMemory, createHierarchicalMemory, createInMemoryGraph, createInMemoryPersonalization, fileChatMemory, fileVectorMemory, matchesFilter, milvusVectorStore, mongoAtlasVectorStore, pgvector, pinecone, qdrant, redisChatMemory, redisVectorMemory, renderProfileContext, sqliteChatMemory, supabaseVectorStore, tursoChatMemory, upstashVector, weaviateVectorStore };
|
package/dist/index.js
CHANGED
|
@@ -904,6 +904,167 @@ function supabaseVectorStore(config) {
|
|
|
904
904
|
};
|
|
905
905
|
}
|
|
906
906
|
|
|
907
|
+
// src/vector/weaviate.ts
|
|
908
|
+
async function call5(config, method, path, body) {
|
|
909
|
+
const fetchImpl = config.fetch ?? globalThis.fetch;
|
|
910
|
+
const response = await fetchImpl(`${config.url}${path}`, {
|
|
911
|
+
method,
|
|
912
|
+
headers: {
|
|
913
|
+
"content-type": "application/json",
|
|
914
|
+
...config.apiKey ? { authorization: `Bearer ${config.apiKey}` } : {}
|
|
915
|
+
},
|
|
916
|
+
body: body === void 0 ? void 0 : JSON.stringify(body)
|
|
917
|
+
});
|
|
918
|
+
const text = await response.text();
|
|
919
|
+
if (!response.ok) throw new Error(`weaviate ${response.status}: ${text.slice(0, 200)}`);
|
|
920
|
+
return text.length > 0 ? JSON.parse(text) : {};
|
|
921
|
+
}
|
|
922
|
+
function weaviateVectorStore(config) {
|
|
923
|
+
const defaultTopK = Math.max(1, config.topK ?? 10);
|
|
924
|
+
const className = config.className;
|
|
925
|
+
return {
|
|
926
|
+
async store(docs) {
|
|
927
|
+
if (docs.length === 0) return;
|
|
928
|
+
await call5(config, "POST", "/v1/batch/objects", {
|
|
929
|
+
objects: docs.map((d) => ({
|
|
930
|
+
class: className,
|
|
931
|
+
id: d.id,
|
|
932
|
+
properties: { content: d.content, ...d.metadata ?? {} },
|
|
933
|
+
vector: d.embedding
|
|
934
|
+
}))
|
|
935
|
+
});
|
|
936
|
+
},
|
|
937
|
+
async search(embedding, options = {}) {
|
|
938
|
+
const topK = options.topK ?? defaultTopK;
|
|
939
|
+
const threshold = options.threshold ?? 0;
|
|
940
|
+
const query = `{
|
|
941
|
+
Get {
|
|
942
|
+
${className}(nearVector: { vector: [${embedding.join(",")}] }, limit: ${topK}) {
|
|
943
|
+
content
|
|
944
|
+
_additional { id certainty }
|
|
945
|
+
}
|
|
946
|
+
}
|
|
947
|
+
}`;
|
|
948
|
+
const result = await call5(config, "POST", "/v1/graphql", { query });
|
|
949
|
+
const rows = result.data?.Get?.[className] ?? [];
|
|
950
|
+
return rows.map((row) => ({
|
|
951
|
+
id: String(row._additional?.id ?? ""),
|
|
952
|
+
content: String(row.content ?? ""),
|
|
953
|
+
score: row._additional?.certainty ?? 0,
|
|
954
|
+
metadata: row
|
|
955
|
+
})).filter((r) => (r.score ?? 0) >= threshold);
|
|
956
|
+
},
|
|
957
|
+
async delete(ids) {
|
|
958
|
+
for (const id of ids) {
|
|
959
|
+
await call5(config, "DELETE", `/v1/objects/${className}/${id}`);
|
|
960
|
+
}
|
|
961
|
+
}
|
|
962
|
+
};
|
|
963
|
+
}
|
|
964
|
+
|
|
965
|
+
// src/vector/milvus.ts
|
|
966
|
+
async function call6(config, path, body) {
|
|
967
|
+
const fetchImpl = config.fetch ?? globalThis.fetch;
|
|
968
|
+
const response = await fetchImpl(`${config.url}${path}`, {
|
|
969
|
+
method: "POST",
|
|
970
|
+
headers: {
|
|
971
|
+
"content-type": "application/json",
|
|
972
|
+
...config.token ? { authorization: `Bearer ${config.token}` } : {}
|
|
973
|
+
},
|
|
974
|
+
body: JSON.stringify(body)
|
|
975
|
+
});
|
|
976
|
+
const text = await response.text();
|
|
977
|
+
if (!response.ok) throw new Error(`milvus ${response.status}: ${text.slice(0, 200)}`);
|
|
978
|
+
return text.length > 0 ? JSON.parse(text) : {};
|
|
979
|
+
}
|
|
980
|
+
function milvusVectorStore(config) {
|
|
981
|
+
const defaultTopK = Math.max(1, config.topK ?? 10);
|
|
982
|
+
const vectorField = config.vectorField ?? "vector";
|
|
983
|
+
return {
|
|
984
|
+
async store(docs) {
|
|
985
|
+
if (docs.length === 0) return;
|
|
986
|
+
await call6(config, "/v2/vectordb/entities/upsert", {
|
|
987
|
+
collectionName: config.collection,
|
|
988
|
+
data: docs.map((d) => ({
|
|
989
|
+
id: d.id,
|
|
990
|
+
[vectorField]: d.embedding,
|
|
991
|
+
content: d.content,
|
|
992
|
+
metadata: d.metadata ?? {}
|
|
993
|
+
}))
|
|
994
|
+
});
|
|
995
|
+
},
|
|
996
|
+
async search(embedding, options = {}) {
|
|
997
|
+
const topK = options.topK ?? defaultTopK;
|
|
998
|
+
const threshold = options.threshold ?? 0;
|
|
999
|
+
const result = await call6(config, "/v2/vectordb/entities/search", {
|
|
1000
|
+
collectionName: config.collection,
|
|
1001
|
+
data: [embedding],
|
|
1002
|
+
annsField: vectorField,
|
|
1003
|
+
limit: topK,
|
|
1004
|
+
outputFields: ["content", "metadata"]
|
|
1005
|
+
});
|
|
1006
|
+
return (result.data ?? []).map((m) => ({
|
|
1007
|
+
id: String(m.id),
|
|
1008
|
+
content: String(m.content ?? ""),
|
|
1009
|
+
score: 1 - m.distance,
|
|
1010
|
+
metadata: m.metadata
|
|
1011
|
+
})).filter((r) => (r.score ?? 0) >= threshold);
|
|
1012
|
+
},
|
|
1013
|
+
async delete(ids) {
|
|
1014
|
+
if (ids.length === 0) return;
|
|
1015
|
+
await call6(config, "/v2/vectordb/entities/delete", {
|
|
1016
|
+
collectionName: config.collection,
|
|
1017
|
+
filter: `id in [${ids.map((id) => `"${id}"`).join(",")}]`
|
|
1018
|
+
});
|
|
1019
|
+
}
|
|
1020
|
+
};
|
|
1021
|
+
}
|
|
1022
|
+
|
|
1023
|
+
// src/vector/mongo-atlas.ts
|
|
1024
|
+
function mongoAtlasVectorStore(config) {
|
|
1025
|
+
const defaultTopK = Math.max(1, config.topK ?? 10);
|
|
1026
|
+
const vectorField = config.vectorField ?? "embedding";
|
|
1027
|
+
return {
|
|
1028
|
+
async store(docs) {
|
|
1029
|
+
if (docs.length === 0) return;
|
|
1030
|
+
await config.collection.insertMany(docs.map((d) => ({
|
|
1031
|
+
_id: d.id,
|
|
1032
|
+
content: d.content,
|
|
1033
|
+
[vectorField]: d.embedding,
|
|
1034
|
+
metadata: d.metadata ?? {}
|
|
1035
|
+
})));
|
|
1036
|
+
},
|
|
1037
|
+
async search(embedding, options = {}) {
|
|
1038
|
+
const topK = options.topK ?? defaultTopK;
|
|
1039
|
+
const threshold = options.threshold ?? 0;
|
|
1040
|
+
const numCandidates = config.numCandidates ?? topK * 10;
|
|
1041
|
+
const cursor = config.collection.aggregate([
|
|
1042
|
+
{
|
|
1043
|
+
$vectorSearch: {
|
|
1044
|
+
index: config.indexName,
|
|
1045
|
+
path: vectorField,
|
|
1046
|
+
queryVector: embedding,
|
|
1047
|
+
numCandidates,
|
|
1048
|
+
limit: topK
|
|
1049
|
+
}
|
|
1050
|
+
},
|
|
1051
|
+
{ $project: { content: 1, metadata: 1, score: { $meta: "vectorSearchScore" } } }
|
|
1052
|
+
]);
|
|
1053
|
+
const rows = await cursor.toArray();
|
|
1054
|
+
return rows.map((row) => ({
|
|
1055
|
+
id: String(row._id),
|
|
1056
|
+
content: String(row.content ?? ""),
|
|
1057
|
+
score: row.score,
|
|
1058
|
+
metadata: row.metadata
|
|
1059
|
+
})).filter((r) => (r.score ?? 0) >= threshold);
|
|
1060
|
+
},
|
|
1061
|
+
async delete(ids) {
|
|
1062
|
+
if (ids.length === 0) return;
|
|
1063
|
+
await config.collection.deleteMany({ _id: { $in: ids } });
|
|
1064
|
+
}
|
|
1065
|
+
};
|
|
1066
|
+
}
|
|
1067
|
+
|
|
907
1068
|
// src/encrypted.ts
|
|
908
1069
|
function toBase64(bytes) {
|
|
909
1070
|
if (typeof Buffer !== "undefined") return Buffer.from(bytes).toString("base64");
|
|
@@ -1046,6 +1207,6 @@ function createHierarchicalMemory(options) {
|
|
|
1046
1207
|
};
|
|
1047
1208
|
}
|
|
1048
1209
|
|
|
1049
|
-
export { chroma, createEncryptedMemory, createHierarchicalMemory, createInMemoryGraph, createInMemoryPersonalization, fileChatMemory, fileVectorMemory, matchesFilter, pgvector, pinecone, qdrant, redisChatMemory, redisVectorMemory, renderProfileContext, sqliteChatMemory, supabaseVectorStore, tursoChatMemory, upstashVector };
|
|
1210
|
+
export { chroma, createEncryptedMemory, createHierarchicalMemory, createInMemoryGraph, createInMemoryPersonalization, fileChatMemory, fileVectorMemory, matchesFilter, milvusVectorStore, mongoAtlasVectorStore, pgvector, pinecone, qdrant, redisChatMemory, redisVectorMemory, renderProfileContext, sqliteChatMemory, supabaseVectorStore, tursoChatMemory, upstashVector, weaviateVectorStore };
|
|
1050
1211
|
//# sourceMappingURL=index.js.map
|
|
1051
1212
|
//# sourceMappingURL=index.js.map
|