convex-agent-knowledge 0.0.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/LICENSE +73 -0
- package/README.md +156 -0
- package/dist/client/chunking.d.ts +7 -0
- package/dist/client/chunking.d.ts.map +1 -0
- package/dist/client/chunking.js +36 -0
- package/dist/client/chunking.js.map +1 -0
- package/dist/client/extraction.d.ts +9 -0
- package/dist/client/extraction.d.ts.map +1 -0
- package/dist/client/extraction.js +88 -0
- package/dist/client/extraction.js.map +1 -0
- package/dist/client/hash.d.ts +3 -0
- package/dist/client/hash.d.ts.map +1 -0
- package/dist/client/hash.js +17 -0
- package/dist/client/hash.js.map +1 -0
- package/dist/client/index.d.ts +99 -0
- package/dist/client/index.d.ts.map +1 -0
- package/dist/client/index.js +194 -0
- package/dist/client/index.js.map +1 -0
- package/dist/client/types.d.ts +126 -0
- package/dist/client/types.d.ts.map +1 -0
- package/dist/client/types.js +2 -0
- package/dist/client/types.js.map +1 -0
- package/dist/component/_generated/api.d.ts +40 -0
- package/dist/component/_generated/api.d.ts.map +1 -0
- package/dist/component/_generated/api.js +31 -0
- package/dist/component/_generated/api.js.map +1 -0
- package/dist/component/_generated/component.d.ts +277 -0
- package/dist/component/_generated/component.d.ts.map +1 -0
- package/dist/component/_generated/component.js +11 -0
- package/dist/component/_generated/component.js.map +1 -0
- package/dist/component/_generated/dataModel.d.ts +46 -0
- package/dist/component/_generated/dataModel.d.ts.map +1 -0
- package/dist/component/_generated/dataModel.js +11 -0
- package/dist/component/_generated/dataModel.js.map +1 -0
- package/dist/component/_generated/server.d.ts +121 -0
- package/dist/component/_generated/server.d.ts.map +1 -0
- package/dist/component/_generated/server.js +78 -0
- package/dist/component/_generated/server.js.map +1 -0
- package/dist/component/actions.d.ts +12 -0
- package/dist/component/actions.d.ts.map +1 -0
- package/dist/component/actions.js +42 -0
- package/dist/component/actions.js.map +1 -0
- package/dist/component/convex.config.d.ts +3 -0
- package/dist/component/convex.config.d.ts.map +1 -0
- package/dist/component/convex.config.js +4 -0
- package/dist/component/convex.config.js.map +1 -0
- package/dist/component/mutations.d.ts +85 -0
- package/dist/component/mutations.d.ts.map +1 -0
- package/dist/component/mutations.js +407 -0
- package/dist/component/mutations.js.map +1 -0
- package/dist/component/queries.d.ts +95 -0
- package/dist/component/queries.d.ts.map +1 -0
- package/dist/component/queries.js +181 -0
- package/dist/component/queries.js.map +1 -0
- package/dist/component/schema.d.ts +442 -0
- package/dist/component/schema.d.ts.map +1 -0
- package/dist/component/schema.js +140 -0
- package/dist/component/schema.js.map +1 -0
- package/dist/component/validators.d.ts +158 -0
- package/dist/component/validators.d.ts.map +1 -0
- package/dist/component/validators.js +90 -0
- package/dist/component/validators.js.map +1 -0
- package/dist/node/index.d.ts +3 -0
- package/dist/node/index.d.ts.map +1 -0
- package/dist/node/index.js +2 -0
- package/dist/node/index.js.map +1 -0
- package/dist/node/neo4j.d.ts +5 -0
- package/dist/node/neo4j.d.ts.map +1 -0
- package/dist/node/neo4j.js +147 -0
- package/dist/node/neo4j.js.map +1 -0
- package/dist/shared/ranking.d.ts +17 -0
- package/dist/shared/ranking.d.ts.map +1 -0
- package/dist/shared/ranking.js +44 -0
- package/dist/shared/ranking.js.map +1 -0
- package/package.json +84 -0
- package/src/client/chunking.test.ts +25 -0
- package/src/client/chunking.ts +45 -0
- package/src/client/extraction.test.ts +15 -0
- package/src/client/extraction.ts +108 -0
- package/src/client/hash.test.ts +17 -0
- package/src/client/hash.ts +17 -0
- package/src/client/index.ts +307 -0
- package/src/client/types.ts +141 -0
- package/src/component/_generated/api.ts +56 -0
- package/src/component/_generated/component.ts +310 -0
- package/src/component/_generated/dataModel.ts +60 -0
- package/src/component/_generated/server.ts +156 -0
- package/src/component/actions.ts +47 -0
- package/src/component/convex.config.ts +5 -0
- package/src/component/mutations.ts +445 -0
- package/src/component/queries.ts +202 -0
- package/src/component/schema.ts +161 -0
- package/src/component/validators.ts +104 -0
- package/src/node/index.ts +2 -0
- package/src/node/neo4j.ts +210 -0
- package/src/shared/ranking.test.ts +30 -0
- package/src/shared/ranking.ts +64 -0
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
export type RankedMemoryCard = {
|
|
2
|
+
memoryId: string;
|
|
3
|
+
score: number;
|
|
4
|
+
semanticScore?: number;
|
|
5
|
+
graphScore?: number;
|
|
6
|
+
importance?: number;
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
export function clamp(value: number, min = 0, max = 1) {
|
|
10
|
+
return Math.min(max, Math.max(min, value));
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function fuseMemoryScores<T extends RankedMemoryCard>(
|
|
14
|
+
semanticCards: T[],
|
|
15
|
+
graphCards: T[],
|
|
16
|
+
options?: {
|
|
17
|
+
semanticWeight?: number;
|
|
18
|
+
graphWeight?: number;
|
|
19
|
+
importanceWeight?: number;
|
|
20
|
+
limit?: number;
|
|
21
|
+
},
|
|
22
|
+
) {
|
|
23
|
+
const semanticWeight = options?.semanticWeight ?? 0.65;
|
|
24
|
+
const graphWeight = options?.graphWeight ?? 0.25;
|
|
25
|
+
const importanceWeight = options?.importanceWeight ?? 0.1;
|
|
26
|
+
const byMemoryId = new Map<string, T>();
|
|
27
|
+
|
|
28
|
+
for (const card of semanticCards) {
|
|
29
|
+
byMemoryId.set(card.memoryId, {
|
|
30
|
+
...card,
|
|
31
|
+
semanticScore: card.semanticScore ?? card.score,
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
for (const graphCard of graphCards) {
|
|
36
|
+
const current = byMemoryId.get(graphCard.memoryId);
|
|
37
|
+
if (current) {
|
|
38
|
+
byMemoryId.set(graphCard.memoryId, {
|
|
39
|
+
...current,
|
|
40
|
+
graphScore: graphCard.graphScore ?? graphCard.score,
|
|
41
|
+
});
|
|
42
|
+
} else {
|
|
43
|
+
byMemoryId.set(graphCard.memoryId, {
|
|
44
|
+
...graphCard,
|
|
45
|
+
graphScore: graphCard.graphScore ?? graphCard.score,
|
|
46
|
+
semanticScore: graphCard.semanticScore ?? 0,
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
return [...byMemoryId.values()]
|
|
52
|
+
.map((card) => {
|
|
53
|
+
const semanticScore = card.semanticScore ?? 0;
|
|
54
|
+
const graphScore = card.graphScore ?? 0;
|
|
55
|
+
const importance = card.importance ?? 0;
|
|
56
|
+
return {
|
|
57
|
+
...card,
|
|
58
|
+
score:
|
|
59
|
+
semanticScore * semanticWeight + graphScore * graphWeight + importance * importanceWeight,
|
|
60
|
+
};
|
|
61
|
+
})
|
|
62
|
+
.sort((a, b) => b.score - a.score)
|
|
63
|
+
.slice(0, options?.limit ?? 10);
|
|
64
|
+
}
|