@batonfx/memory 0.4.2 → 0.4.4
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.
|
@@ -10,6 +10,6 @@ export interface Options {
|
|
|
10
10
|
/** @experimental */
|
|
11
11
|
export declare const make: (options?: Options) => Effect.Effect<Memory.Interface, never, VectorStore | EmbeddingModel.EmbeddingModel>;
|
|
12
12
|
/** @experimental */
|
|
13
|
-
export declare const makeSemanticRecall:
|
|
13
|
+
export declare const makeSemanticRecall: typeof make;
|
|
14
14
|
/** @experimental */
|
|
15
15
|
export declare const layer: (options?: Options) => Layer.Layer<Memory.Memory, never, VectorStore | EmbeddingModel.EmbeddingModel>;
|
package/dist/semantic-recall.js
CHANGED
|
@@ -3,7 +3,7 @@ import { EmbeddingModel, Prompt } from "effect/unstable/ai";
|
|
|
3
3
|
import { Memory } from "@batonfx/core";
|
|
4
4
|
import { VectorStore } from "./vector-store.js";
|
|
5
5
|
const errorMessage = (error) => (error instanceof Error ? `${error.name}: ${error.message}` : String(error));
|
|
6
|
-
const memoryError = (error) =>
|
|
6
|
+
const memoryError = (error) => Memory.MemoryError.make({ message: errorMessage(error) });
|
|
7
7
|
const textPart = (text) => Prompt.makePart("text", { text });
|
|
8
8
|
const textFromParts = (parts) => parts
|
|
9
9
|
.filter((part) => part.type === "text")
|
package/dist/vector-store.d.ts
CHANGED
|
@@ -40,7 +40,7 @@ export interface Interface {
|
|
|
40
40
|
readonly query: (query: Query) => Effect.Effect<ReadonlyArray<Match>, VectorStoreError>;
|
|
41
41
|
readonly delete: (input: DeleteInput) => Effect.Effect<void, VectorStoreError>;
|
|
42
42
|
}
|
|
43
|
-
declare const VectorStore_base: Context.ServiceClass<VectorStore, "@batonfx/memory/VectorStore", Interface>;
|
|
43
|
+
declare const VectorStore_base: Context.ServiceClass<VectorStore, "@batonfx/memory/vector-store/VectorStore", Interface>;
|
|
44
44
|
/** @experimental */
|
|
45
45
|
export declare class VectorStore extends VectorStore_base {
|
|
46
46
|
}
|
package/dist/vector-store.js
CHANGED
|
@@ -6,7 +6,7 @@ export class VectorStoreError extends Schema.TaggedErrorClass()("@batonfx/memory
|
|
|
6
6
|
}) {
|
|
7
7
|
}
|
|
8
8
|
/** @experimental */
|
|
9
|
-
export class VectorStore extends Context.Service()("@batonfx/memory/VectorStore") {
|
|
9
|
+
export class VectorStore extends Context.Service()("@batonfx/memory/vector-store/VectorStore") {
|
|
10
10
|
}
|
|
11
11
|
const storageKey = (key, id) => JSON.stringify([key.agent, key.subject, id]);
|
|
12
12
|
const sameKey = (left, right) => left.agent === right.agent && left.subject === right.subject;
|
|
@@ -14,7 +14,7 @@ const validateVector = (label, vector) => {
|
|
|
14
14
|
const invalid = vector.find((value) => !Number.isFinite(value));
|
|
15
15
|
return invalid === undefined
|
|
16
16
|
? Effect.void
|
|
17
|
-
: Effect.fail(
|
|
17
|
+
: Effect.fail(VectorStoreError.make({ message: `${label} contains a non-finite value` }));
|
|
18
18
|
};
|
|
19
19
|
const cosine = (left, right) => {
|
|
20
20
|
let dot = 0;
|
|
@@ -54,9 +54,9 @@ const make = Ref.make(HashMap.empty()).pipe(Effect.map((documents) => ({
|
|
|
54
54
|
if (!sameKey(document.key, input.key))
|
|
55
55
|
continue;
|
|
56
56
|
if (document.embedding.length !== input.embedding.length) {
|
|
57
|
-
return yield*
|
|
57
|
+
return yield* VectorStoreError.make({
|
|
58
58
|
message: `document ${document.id} embedding dimension ${document.embedding.length} does not match query dimension ${input.embedding.length}`,
|
|
59
|
-
})
|
|
59
|
+
});
|
|
60
60
|
}
|
|
61
61
|
const score = cosine(document.embedding, input.embedding);
|
|
62
62
|
if (input.minScore !== undefined && score < input.minScore)
|
package/dist/working-memory.d.ts
CHANGED
|
@@ -14,6 +14,6 @@ export interface Options {
|
|
|
14
14
|
/** @experimental */
|
|
15
15
|
export declare const make: (options?: Options) => Effect.Effect<Memory.Interface>;
|
|
16
16
|
/** @experimental */
|
|
17
|
-
export declare const makeWorkingMemory:
|
|
17
|
+
export declare const makeWorkingMemory: typeof make;
|
|
18
18
|
/** @experimental */
|
|
19
19
|
export declare const layer: (options?: Options) => Layer.Layer<Memory.Memory>;
|
package/dist/working-memory.js
CHANGED
|
@@ -7,7 +7,7 @@ const emptyState = {
|
|
|
7
7
|
};
|
|
8
8
|
const defaultSummaryPrompt = "Summarize the conversation memory while preserving stable user preferences and facts.";
|
|
9
9
|
const errorMessage = (error) => (error instanceof Error ? `${error.name}: ${error.message}` : String(error));
|
|
10
|
-
const memoryError = (error) =>
|
|
10
|
+
const memoryError = (error) => Memory.MemoryError.make({ message: errorMessage(error) });
|
|
11
11
|
const keyId = (key) => JSON.stringify([key.agent, key.subject]);
|
|
12
12
|
const textPart = (text) => Prompt.makePart("text", { text });
|
|
13
13
|
const textFromParts = (parts) => parts
|
|
@@ -59,7 +59,7 @@ const renderSummaryPrompt = (prompt, summary, overflow) => [
|
|
|
59
59
|
`New messages:\n${overflow.map(formatItem).join("\n")}`,
|
|
60
60
|
"Return only the updated summary.",
|
|
61
61
|
].join("\n\n");
|
|
62
|
-
const summarizeOverflow = (options, summary, overflow) => Effect.gen(function* () {
|
|
62
|
+
const summarizeOverflow = (options, summary, overflow) => Effect.scoped(Layer.build(options.model).pipe(Effect.flatMap((context) => Effect.gen(function* () {
|
|
63
63
|
const model = yield* LanguageModel.LanguageModel;
|
|
64
64
|
const response = yield* model.generateText({
|
|
65
65
|
prompt: renderSummaryPrompt(options.prompt ?? defaultSummaryPrompt, summary, overflow),
|
|
@@ -68,7 +68,7 @@ const summarizeOverflow = (options, summary, overflow) => Effect.gen(function* (
|
|
|
68
68
|
});
|
|
69
69
|
const text = response.text.trim();
|
|
70
70
|
return text.length === 0 ? summary : text;
|
|
71
|
-
}).pipe(Effect.provide(
|
|
71
|
+
}).pipe(Effect.provide(context))), Effect.mapError(memoryError)));
|
|
72
72
|
const recallItems = (state) => [
|
|
73
73
|
...(state.summary === undefined
|
|
74
74
|
? []
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "https://json.schemastore.org/package.json",
|
|
3
3
|
"name": "@batonfx/memory",
|
|
4
|
-
"version": "0.4.
|
|
4
|
+
"version": "0.4.4",
|
|
5
5
|
"private": false,
|
|
6
6
|
"type": "module",
|
|
7
7
|
"exports": {
|
|
@@ -17,13 +17,13 @@
|
|
|
17
17
|
"typecheck": "bun tsc --noEmit"
|
|
18
18
|
},
|
|
19
19
|
"dependencies": {
|
|
20
|
-
"@batonfx/core": "0.4.
|
|
20
|
+
"@batonfx/core": "0.4.4",
|
|
21
21
|
"effect": "4.0.0-beta.93"
|
|
22
22
|
},
|
|
23
23
|
"devDependencies": {
|
|
24
24
|
"@effect/vitest": "4.0.0-beta.93",
|
|
25
25
|
"@types/bun": "1.3.13",
|
|
26
|
-
"typescript": "
|
|
26
|
+
"typescript": "7.0.2",
|
|
27
27
|
"vitest": "4.0.16"
|
|
28
28
|
},
|
|
29
29
|
"description": "Non-durable memory implementations for Baton agents",
|