@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.cjs
CHANGED
|
@@ -906,6 +906,167 @@ function supabaseVectorStore(config) {
|
|
|
906
906
|
};
|
|
907
907
|
}
|
|
908
908
|
|
|
909
|
+
// src/vector/weaviate.ts
|
|
910
|
+
async function call5(config, method, path, body) {
|
|
911
|
+
const fetchImpl = config.fetch ?? globalThis.fetch;
|
|
912
|
+
const response = await fetchImpl(`${config.url}${path}`, {
|
|
913
|
+
method,
|
|
914
|
+
headers: {
|
|
915
|
+
"content-type": "application/json",
|
|
916
|
+
...config.apiKey ? { authorization: `Bearer ${config.apiKey}` } : {}
|
|
917
|
+
},
|
|
918
|
+
body: body === void 0 ? void 0 : JSON.stringify(body)
|
|
919
|
+
});
|
|
920
|
+
const text = await response.text();
|
|
921
|
+
if (!response.ok) throw new Error(`weaviate ${response.status}: ${text.slice(0, 200)}`);
|
|
922
|
+
return text.length > 0 ? JSON.parse(text) : {};
|
|
923
|
+
}
|
|
924
|
+
function weaviateVectorStore(config) {
|
|
925
|
+
const defaultTopK = Math.max(1, config.topK ?? 10);
|
|
926
|
+
const className = config.className;
|
|
927
|
+
return {
|
|
928
|
+
async store(docs) {
|
|
929
|
+
if (docs.length === 0) return;
|
|
930
|
+
await call5(config, "POST", "/v1/batch/objects", {
|
|
931
|
+
objects: docs.map((d) => ({
|
|
932
|
+
class: className,
|
|
933
|
+
id: d.id,
|
|
934
|
+
properties: { content: d.content, ...d.metadata ?? {} },
|
|
935
|
+
vector: d.embedding
|
|
936
|
+
}))
|
|
937
|
+
});
|
|
938
|
+
},
|
|
939
|
+
async search(embedding, options = {}) {
|
|
940
|
+
const topK = options.topK ?? defaultTopK;
|
|
941
|
+
const threshold = options.threshold ?? 0;
|
|
942
|
+
const query = `{
|
|
943
|
+
Get {
|
|
944
|
+
${className}(nearVector: { vector: [${embedding.join(",")}] }, limit: ${topK}) {
|
|
945
|
+
content
|
|
946
|
+
_additional { id certainty }
|
|
947
|
+
}
|
|
948
|
+
}
|
|
949
|
+
}`;
|
|
950
|
+
const result = await call5(config, "POST", "/v1/graphql", { query });
|
|
951
|
+
const rows = result.data?.Get?.[className] ?? [];
|
|
952
|
+
return rows.map((row) => ({
|
|
953
|
+
id: String(row._additional?.id ?? ""),
|
|
954
|
+
content: String(row.content ?? ""),
|
|
955
|
+
score: row._additional?.certainty ?? 0,
|
|
956
|
+
metadata: row
|
|
957
|
+
})).filter((r) => (r.score ?? 0) >= threshold);
|
|
958
|
+
},
|
|
959
|
+
async delete(ids) {
|
|
960
|
+
for (const id of ids) {
|
|
961
|
+
await call5(config, "DELETE", `/v1/objects/${className}/${id}`);
|
|
962
|
+
}
|
|
963
|
+
}
|
|
964
|
+
};
|
|
965
|
+
}
|
|
966
|
+
|
|
967
|
+
// src/vector/milvus.ts
|
|
968
|
+
async function call6(config, path, body) {
|
|
969
|
+
const fetchImpl = config.fetch ?? globalThis.fetch;
|
|
970
|
+
const response = await fetchImpl(`${config.url}${path}`, {
|
|
971
|
+
method: "POST",
|
|
972
|
+
headers: {
|
|
973
|
+
"content-type": "application/json",
|
|
974
|
+
...config.token ? { authorization: `Bearer ${config.token}` } : {}
|
|
975
|
+
},
|
|
976
|
+
body: JSON.stringify(body)
|
|
977
|
+
});
|
|
978
|
+
const text = await response.text();
|
|
979
|
+
if (!response.ok) throw new Error(`milvus ${response.status}: ${text.slice(0, 200)}`);
|
|
980
|
+
return text.length > 0 ? JSON.parse(text) : {};
|
|
981
|
+
}
|
|
982
|
+
function milvusVectorStore(config) {
|
|
983
|
+
const defaultTopK = Math.max(1, config.topK ?? 10);
|
|
984
|
+
const vectorField = config.vectorField ?? "vector";
|
|
985
|
+
return {
|
|
986
|
+
async store(docs) {
|
|
987
|
+
if (docs.length === 0) return;
|
|
988
|
+
await call6(config, "/v2/vectordb/entities/upsert", {
|
|
989
|
+
collectionName: config.collection,
|
|
990
|
+
data: docs.map((d) => ({
|
|
991
|
+
id: d.id,
|
|
992
|
+
[vectorField]: d.embedding,
|
|
993
|
+
content: d.content,
|
|
994
|
+
metadata: d.metadata ?? {}
|
|
995
|
+
}))
|
|
996
|
+
});
|
|
997
|
+
},
|
|
998
|
+
async search(embedding, options = {}) {
|
|
999
|
+
const topK = options.topK ?? defaultTopK;
|
|
1000
|
+
const threshold = options.threshold ?? 0;
|
|
1001
|
+
const result = await call6(config, "/v2/vectordb/entities/search", {
|
|
1002
|
+
collectionName: config.collection,
|
|
1003
|
+
data: [embedding],
|
|
1004
|
+
annsField: vectorField,
|
|
1005
|
+
limit: topK,
|
|
1006
|
+
outputFields: ["content", "metadata"]
|
|
1007
|
+
});
|
|
1008
|
+
return (result.data ?? []).map((m) => ({
|
|
1009
|
+
id: String(m.id),
|
|
1010
|
+
content: String(m.content ?? ""),
|
|
1011
|
+
score: 1 - m.distance,
|
|
1012
|
+
metadata: m.metadata
|
|
1013
|
+
})).filter((r) => (r.score ?? 0) >= threshold);
|
|
1014
|
+
},
|
|
1015
|
+
async delete(ids) {
|
|
1016
|
+
if (ids.length === 0) return;
|
|
1017
|
+
await call6(config, "/v2/vectordb/entities/delete", {
|
|
1018
|
+
collectionName: config.collection,
|
|
1019
|
+
filter: `id in [${ids.map((id) => `"${id}"`).join(",")}]`
|
|
1020
|
+
});
|
|
1021
|
+
}
|
|
1022
|
+
};
|
|
1023
|
+
}
|
|
1024
|
+
|
|
1025
|
+
// src/vector/mongo-atlas.ts
|
|
1026
|
+
function mongoAtlasVectorStore(config) {
|
|
1027
|
+
const defaultTopK = Math.max(1, config.topK ?? 10);
|
|
1028
|
+
const vectorField = config.vectorField ?? "embedding";
|
|
1029
|
+
return {
|
|
1030
|
+
async store(docs) {
|
|
1031
|
+
if (docs.length === 0) return;
|
|
1032
|
+
await config.collection.insertMany(docs.map((d) => ({
|
|
1033
|
+
_id: d.id,
|
|
1034
|
+
content: d.content,
|
|
1035
|
+
[vectorField]: d.embedding,
|
|
1036
|
+
metadata: d.metadata ?? {}
|
|
1037
|
+
})));
|
|
1038
|
+
},
|
|
1039
|
+
async search(embedding, options = {}) {
|
|
1040
|
+
const topK = options.topK ?? defaultTopK;
|
|
1041
|
+
const threshold = options.threshold ?? 0;
|
|
1042
|
+
const numCandidates = config.numCandidates ?? topK * 10;
|
|
1043
|
+
const cursor = config.collection.aggregate([
|
|
1044
|
+
{
|
|
1045
|
+
$vectorSearch: {
|
|
1046
|
+
index: config.indexName,
|
|
1047
|
+
path: vectorField,
|
|
1048
|
+
queryVector: embedding,
|
|
1049
|
+
numCandidates,
|
|
1050
|
+
limit: topK
|
|
1051
|
+
}
|
|
1052
|
+
},
|
|
1053
|
+
{ $project: { content: 1, metadata: 1, score: { $meta: "vectorSearchScore" } } }
|
|
1054
|
+
]);
|
|
1055
|
+
const rows = await cursor.toArray();
|
|
1056
|
+
return rows.map((row) => ({
|
|
1057
|
+
id: String(row._id),
|
|
1058
|
+
content: String(row.content ?? ""),
|
|
1059
|
+
score: row.score,
|
|
1060
|
+
metadata: row.metadata
|
|
1061
|
+
})).filter((r) => (r.score ?? 0) >= threshold);
|
|
1062
|
+
},
|
|
1063
|
+
async delete(ids) {
|
|
1064
|
+
if (ids.length === 0) return;
|
|
1065
|
+
await config.collection.deleteMany({ _id: { $in: ids } });
|
|
1066
|
+
}
|
|
1067
|
+
};
|
|
1068
|
+
}
|
|
1069
|
+
|
|
909
1070
|
// src/encrypted.ts
|
|
910
1071
|
function toBase64(bytes) {
|
|
911
1072
|
if (typeof Buffer !== "undefined") return Buffer.from(bytes).toString("base64");
|
|
@@ -1056,6 +1217,8 @@ exports.createInMemoryPersonalization = createInMemoryPersonalization;
|
|
|
1056
1217
|
exports.fileChatMemory = fileChatMemory;
|
|
1057
1218
|
exports.fileVectorMemory = fileVectorMemory;
|
|
1058
1219
|
exports.matchesFilter = matchesFilter;
|
|
1220
|
+
exports.milvusVectorStore = milvusVectorStore;
|
|
1221
|
+
exports.mongoAtlasVectorStore = mongoAtlasVectorStore;
|
|
1059
1222
|
exports.pgvector = pgvector;
|
|
1060
1223
|
exports.pinecone = pinecone;
|
|
1061
1224
|
exports.qdrant = qdrant;
|
|
@@ -1066,5 +1229,6 @@ exports.sqliteChatMemory = sqliteChatMemory;
|
|
|
1066
1229
|
exports.supabaseVectorStore = supabaseVectorStore;
|
|
1067
1230
|
exports.tursoChatMemory = tursoChatMemory;
|
|
1068
1231
|
exports.upstashVector = upstashVector;
|
|
1232
|
+
exports.weaviateVectorStore = weaviateVectorStore;
|
|
1069
1233
|
//# sourceMappingURL=index.cjs.map
|
|
1070
1234
|
//# sourceMappingURL=index.cjs.map
|