kernl 0.6.2 → 0.6.3
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/.turbo/turbo-build.log +1 -1
- package/.turbo/turbo-check-types.log +1 -1
- package/CHANGELOG.md +30 -0
- package/dist/agent/__tests__/concurrency.test.js +1 -1
- package/dist/agent/__tests__/run.test.js +1 -1
- package/dist/{types/agent.d.ts → agent/types.d.ts} +2 -2
- package/dist/agent/types.d.ts.map +1 -0
- package/dist/agent.d.ts +36 -4
- package/dist/agent.d.ts.map +1 -1
- package/dist/agent.js +58 -0
- package/dist/api/models/thread.d.ts +1 -1
- package/dist/api/resources/threads/threads.d.ts +1 -1
- package/dist/api/resources/threads/threads.d.ts.map +1 -1
- package/dist/api/resources/threads/threads.js +1 -1
- package/dist/api/resources/threads/types.d.ts +2 -2
- package/dist/api/resources/threads/types.d.ts.map +1 -1
- package/dist/context.d.ts +4 -4
- package/dist/context.d.ts.map +1 -1
- package/dist/guardrail.d.ts +2 -2
- package/dist/index.d.ts +5 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -3
- package/dist/internal.d.ts +2 -2
- package/dist/internal.js +1 -1
- package/dist/kernl/index.d.ts +1 -1
- package/dist/kernl/index.d.ts.map +1 -1
- package/dist/kernl/index.js +0 -1
- package/dist/kernl/kernl.d.ts +7 -18
- package/dist/kernl/kernl.d.ts.map +1 -1
- package/dist/kernl/kernl.js +29 -29
- package/dist/kernl/types.d.ts +91 -0
- package/dist/kernl/types.d.ts.map +1 -0
- package/dist/lib/error.d.ts +2 -2
- package/dist/lifecycle.d.ts +2 -2
- package/dist/memory/codec.d.ts +32 -0
- package/dist/memory/codec.d.ts.map +1 -0
- package/dist/memory/codec.js +97 -0
- package/dist/memory/codecs/domain.d.ts +34 -0
- package/dist/memory/codecs/domain.d.ts.map +1 -0
- package/dist/memory/codecs/domain.js +99 -0
- package/dist/memory/codecs/identity.d.ts +12 -0
- package/dist/memory/codecs/identity.d.ts.map +1 -0
- package/dist/memory/codecs/identity.js +17 -0
- package/dist/memory/codecs/index.d.ts +31 -0
- package/dist/memory/codecs/index.d.ts.map +1 -0
- package/dist/memory/codecs/index.js +39 -0
- package/dist/memory/codecs/tpuf.d.ts +38 -0
- package/dist/memory/codecs/tpuf.d.ts.map +1 -0
- package/dist/memory/codecs/tpuf.js +90 -0
- package/dist/memory/encoder.d.ts +29 -0
- package/dist/memory/encoder.d.ts.map +1 -0
- package/dist/memory/encoder.js +45 -0
- package/dist/memory/handle.d.ts +89 -0
- package/dist/memory/handle.d.ts.map +1 -0
- package/dist/memory/handle.js +128 -0
- package/dist/memory/index.d.ts +12 -0
- package/dist/memory/index.d.ts.map +1 -0
- package/dist/memory/index.js +7 -0
- package/dist/memory/indexes.d.ts +91 -0
- package/dist/memory/indexes.d.ts.map +1 -0
- package/dist/memory/indexes.js +7 -0
- package/dist/memory/memory.d.ts +51 -0
- package/dist/memory/memory.d.ts.map +1 -0
- package/dist/memory/memory.js +107 -0
- package/dist/memory/schema.d.ts +41 -0
- package/dist/memory/schema.d.ts.map +1 -0
- package/dist/memory/schema.js +112 -0
- package/dist/memory/store.d.ts +36 -0
- package/dist/memory/store.d.ts.map +1 -0
- package/dist/memory/store.js +4 -0
- package/dist/memory/types.d.ts +250 -0
- package/dist/memory/types.d.ts.map +1 -0
- package/dist/memory/types.js +4 -0
- package/dist/storage/base.d.ts +6 -1
- package/dist/storage/base.d.ts.map +1 -1
- package/dist/storage/in-memory.d.ts +24 -2
- package/dist/storage/in-memory.d.ts.map +1 -1
- package/dist/storage/in-memory.js +131 -0
- package/dist/storage/thread.d.ts +1 -1
- package/dist/thread/__tests__/integration.test.js +1 -1
- package/dist/thread/__tests__/mock.d.ts +1 -1
- package/dist/thread/__tests__/namespace.test.js +1 -1
- package/dist/thread/__tests__/thread.test.js +1 -1
- package/dist/thread/thread.d.ts +2 -2
- package/dist/thread/thread.d.ts.map +1 -1
- package/dist/{types/thread.d.ts → thread/types.d.ts} +2 -2
- package/dist/thread/types.d.ts.map +1 -0
- package/dist/thread/utils.d.ts +2 -2
- package/dist/thread/utils.d.ts.map +1 -1
- package/package.json +4 -2
- package/src/{types/agent.ts → agent/types.ts} +1 -1
- package/src/agent.ts +78 -2
- package/src/api/__tests__/threads.test.ts +2 -2
- package/src/api/models/thread.ts +1 -1
- package/src/api/resources/threads/events.ts +1 -1
- package/src/api/resources/threads/threads.ts +2 -2
- package/src/api/resources/threads/types.ts +2 -2
- package/src/context.ts +6 -136
- package/src/guardrail.ts +2 -2
- package/src/index.ts +35 -6
- package/src/internal.ts +2 -2
- package/src/kernl/index.ts +8 -0
- package/src/{kernl.ts → kernl/kernl.ts} +40 -3
- package/src/kernl/types.ts +106 -0
- package/src/lib/error.ts +2 -2
- package/src/lifecycle.ts +2 -2
- package/src/memory/codecs/domain.ts +115 -0
- package/src/memory/codecs/identity.ts +28 -0
- package/src/memory/codecs/index.ts +61 -0
- package/src/memory/codecs/tpuf.ts +115 -0
- package/src/memory/encoder.ts +56 -0
- package/src/memory/handle.ts +189 -0
- package/src/memory/index.ts +49 -0
- package/src/memory/indexes.ts +108 -0
- package/src/memory/memory.ts +143 -0
- package/src/memory/schema.ts +142 -0
- package/src/memory/store.ts +47 -0
- package/src/memory/types.ts +282 -0
- package/src/storage/__tests__/in-memory.test.ts +1 -1
- package/src/storage/base.ts +7 -1
- package/src/storage/in-memory.ts +170 -2
- package/src/storage/thread.ts +1 -1
- package/src/thread/__tests__/integration.test.ts +1 -1
- package/src/thread/__tests__/mock.ts +1 -1
- package/src/thread/__tests__/thread.test.ts +1 -1
- package/src/thread/thread.ts +2 -2
- package/src/{types/thread.ts → thread/types.ts} +1 -1
- package/src/thread/utils.ts +2 -2
- package/tsconfig.tsbuildinfo +1 -0
- package/dist/api/__tests__/cursor-page.test.d.ts +0 -2
- package/dist/api/__tests__/cursor-page.test.d.ts.map +0 -1
- package/dist/api/__tests__/cursor-page.test.js +0 -414
- package/dist/api/__tests__/offset-page.test.d.ts +0 -2
- package/dist/api/__tests__/offset-page.test.d.ts.map +0 -1
- package/dist/api/__tests__/offset-page.test.js +0 -510
- package/dist/api/pagination/base.d.ts +0 -48
- package/dist/api/pagination/base.d.ts.map +0 -1
- package/dist/api/pagination/base.js +0 -45
- package/dist/api/pagination/cursor.d.ts +0 -44
- package/dist/api/pagination/cursor.d.ts.map +0 -1
- package/dist/api/pagination/cursor.js +0 -52
- package/dist/api/pagination/offset.d.ts +0 -42
- package/dist/api/pagination/offset.d.ts.map +0 -1
- package/dist/api/pagination/offset.js +0 -55
- package/dist/kernl/threads.d.ts +0 -110
- package/dist/kernl/threads.d.ts.map +0 -1
- package/dist/kernl/threads.js +0 -126
- package/dist/kernl.d.ts +0 -51
- package/dist/kernl.d.ts.map +0 -1
- package/dist/kernl.js +0 -91
- package/dist/types/agent.d.ts.map +0 -1
- package/dist/types/kernl.d.ts +0 -42
- package/dist/types/kernl.d.ts.map +0 -1
- package/dist/types/thread.d.ts.map +0 -1
- package/src/api/__tests__/cursor-page.test.ts +0 -512
- package/src/api/__tests__/offset-page.test.ts +0 -624
- package/src/api/pagination/base.ts +0 -79
- package/src/api/pagination/cursor.ts +0 -86
- package/src/api/pagination/offset.ts +0 -89
- package/src/types/kernl.ts +0 -51
- /package/dist/{types/agent.js → agent/types.js} +0 -0
- /package/dist/{types/kernl.js → kernl/types.js} +0 -0
- /package/dist/{types/thread.js → thread/types.js} +0 -0
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MemoryByte encoder - converts MemoryByte to IndexableByte with embeddings.
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Encoder that converts MemoryByte to IndexableByte.
|
|
6
|
+
*
|
|
7
|
+
* Extracts canonical text from content and computes embeddings.
|
|
8
|
+
*/
|
|
9
|
+
export class MemoryByteEncoder {
|
|
10
|
+
embedder;
|
|
11
|
+
constructor(embedder) {
|
|
12
|
+
this.embedder = embedder;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Encode a MemoryByte to IndexableByte.
|
|
16
|
+
* Extracts text and computes embeddings for each modality.
|
|
17
|
+
*/
|
|
18
|
+
async encode(byte) {
|
|
19
|
+
const text = byte.text;
|
|
20
|
+
const tvec = text ? await this.embed(text) : undefined;
|
|
21
|
+
// TODO: embed other modalities (image, audio, video)
|
|
22
|
+
// const ivec = byte.image ? await this.embedImage(byte.image) : undefined;
|
|
23
|
+
// const avec = byte.audio ? await this.embedAudio(byte.audio) : undefined;
|
|
24
|
+
// const vvec = byte.video ? await this.embedVideo(byte.video) : undefined;
|
|
25
|
+
return {
|
|
26
|
+
text,
|
|
27
|
+
tvec,
|
|
28
|
+
metadata: byte.object ?? null,
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Decode is not implemented - IndexableByte cannot be converted back to MemoryByte.
|
|
33
|
+
*/
|
|
34
|
+
async decode(_indexable) {
|
|
35
|
+
throw new Error("MemoryByteEncoder.decode not implemented");
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Embed a text string.
|
|
39
|
+
* Exposed for query embedding.
|
|
40
|
+
*/
|
|
41
|
+
async embed(text) {
|
|
42
|
+
const result = await this.embedder.embed({ values: [text] });
|
|
43
|
+
return result.embeddings[0] ?? [];
|
|
44
|
+
}
|
|
45
|
+
}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Memory index handle with lazy initialization.
|
|
3
|
+
*/
|
|
4
|
+
import { type SearchIndex, type IndexHandle, type QueryInput, type SearchHit, type DocumentPatch, type UpsertResult, type PatchResult, type DeleteResult, type FieldSchema } from "@kernl-sdk/retrieval";
|
|
5
|
+
import type { IndexMemoryRecord } from "./types.js";
|
|
6
|
+
/**
|
|
7
|
+
* Configuration for MemoryIndexHandle.
|
|
8
|
+
*/
|
|
9
|
+
export interface MemoryIndexHandleConfig {
|
|
10
|
+
/**
|
|
11
|
+
* The underlying search index backend.
|
|
12
|
+
*/
|
|
13
|
+
index: SearchIndex;
|
|
14
|
+
/**
|
|
15
|
+
* Index identifier (e.g., "kernl_memories_index").
|
|
16
|
+
*/
|
|
17
|
+
indexId: string;
|
|
18
|
+
/**
|
|
19
|
+
* Field schema for the memory index.
|
|
20
|
+
*/
|
|
21
|
+
schema: Record<string, FieldSchema>;
|
|
22
|
+
/**
|
|
23
|
+
* Backend-specific options passed to SearchIndex.createIndex().
|
|
24
|
+
*/
|
|
25
|
+
providerOptions?: Record<string, unknown>;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Domain-aware index handle for memory records with lazy initialization.
|
|
29
|
+
*
|
|
30
|
+
* - Wraps a SearchIndex and ensures the memory index is created before any operation.
|
|
31
|
+
* - Normalizes the idiosyncrasies of search adapters (capabilities, weird rules, ... - e.g. tpuf requires vector fields named
|
|
32
|
+
* literally 'vector' - dumb shit like this..)
|
|
33
|
+
*/
|
|
34
|
+
export declare class MemoryIndexHandle implements IndexHandle<IndexMemoryRecord> {
|
|
35
|
+
readonly id: string;
|
|
36
|
+
private readonly index;
|
|
37
|
+
private readonly schema;
|
|
38
|
+
private readonly caps;
|
|
39
|
+
private readonly codecs;
|
|
40
|
+
private readonly providerOptions?;
|
|
41
|
+
private initPromise;
|
|
42
|
+
constructor(config: MemoryIndexHandleConfig);
|
|
43
|
+
/**
|
|
44
|
+
* Ensure memory index exists (lazy initialization).
|
|
45
|
+
*
|
|
46
|
+
* Safe to call multiple times - initialization only runs once.
|
|
47
|
+
*/
|
|
48
|
+
private ensureInit;
|
|
49
|
+
/**
|
|
50
|
+
* Create the memory index if it doesn't exist.
|
|
51
|
+
*/
|
|
52
|
+
private createIndex;
|
|
53
|
+
/**
|
|
54
|
+
* Search for memory records matching the query.
|
|
55
|
+
*
|
|
56
|
+
* Adapts the query to backend capabilities, degrading gracefully
|
|
57
|
+
* when hybrid or multi-signal queries aren't supported.
|
|
58
|
+
*/
|
|
59
|
+
query(input: QueryInput): Promise<SearchHit<IndexMemoryRecord>[]>;
|
|
60
|
+
/**
|
|
61
|
+
* Insert or update memory records in the index.
|
|
62
|
+
*/
|
|
63
|
+
upsert(docs: IndexMemoryRecord | IndexMemoryRecord[]): Promise<UpsertResult>;
|
|
64
|
+
/**
|
|
65
|
+
* Partially update memory records without re-indexing vectors.
|
|
66
|
+
*
|
|
67
|
+
* Note: Patches don't include vector fields so we cast directly.
|
|
68
|
+
* Metadata field type mismatch (JSONObject vs FieldValue) is handled at runtime.
|
|
69
|
+
*/
|
|
70
|
+
patch(patches: DocumentPatch<IndexMemoryRecord> | DocumentPatch<IndexMemoryRecord>[]): Promise<PatchResult>;
|
|
71
|
+
/**
|
|
72
|
+
* Remove memory records from the index.
|
|
73
|
+
*/
|
|
74
|
+
delete(ids: string | string[]): Promise<DeleteResult>;
|
|
75
|
+
/**
|
|
76
|
+
* Add a new field to the index schema.
|
|
77
|
+
*
|
|
78
|
+
* @throws Always throws - dynamic schema modification not supported
|
|
79
|
+
*/
|
|
80
|
+
addField(_field: string, _schema: FieldSchema): Promise<void>;
|
|
81
|
+
/**
|
|
82
|
+
* Get an initialized underlying index handle.
|
|
83
|
+
*
|
|
84
|
+
* Returns a handle typed for UnknownDocument since we encode/decode
|
|
85
|
+
* through the adapter codecs for backend-specific field mapping.
|
|
86
|
+
*/
|
|
87
|
+
private handle;
|
|
88
|
+
}
|
|
89
|
+
//# sourceMappingURL=handle.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"handle.d.ts","sourceRoot":"","sources":["../../src/memory/handle.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAEL,KAAK,WAAW,EAChB,KAAK,WAAW,EAChB,KAAK,UAAU,EACf,KAAK,SAAS,EACd,KAAK,aAAa,EAClB,KAAK,YAAY,EACjB,KAAK,WAAW,EAChB,KAAK,YAAY,EACjB,KAAK,WAAW,EAGjB,MAAM,sBAAsB,CAAC;AAG9B,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AAEjD;;GAEG;AACH,MAAM,WAAW,uBAAuB;IACtC;;OAEG;IACH,KAAK,EAAE,WAAW,CAAC;IAEnB;;OAEG;IACH,OAAO,EAAE,MAAM,CAAC;IAEhB;;OAEG;IACH,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC;IAEpC;;OAEG;IACH,eAAe,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAC3C;AAED;;;;;;GAMG;AACH,qBAAa,iBAAkB,YAAW,WAAW,CAAC,iBAAiB,CAAC;IACtE,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IAEpB,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAc;IACpC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAA8B;IACrD,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAqB;IAC1C,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAgB;IACvC,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAC,CAA0B;IAE3D,OAAO,CAAC,WAAW,CAA8B;gBAErC,MAAM,EAAE,uBAAuB;IAS3C;;;;OAIG;YACW,UAAU;IAUxB;;OAEG;YACW,WAAW;IAqBzB;;;;;OAKG;IACG,KAAK,CAAC,KAAK,EAAE,UAAU,GAAG,OAAO,CAAC,SAAS,CAAC,iBAAiB,CAAC,EAAE,CAAC;IAevE;;OAEG;IACG,MAAM,CACV,IAAI,EAAE,iBAAiB,GAAG,iBAAiB,EAAE,GAC5C,OAAO,CAAC,YAAY,CAAC;IAOxB;;;;;OAKG;IACG,KAAK,CACT,OAAO,EACH,aAAa,CAAC,iBAAiB,CAAC,GAChC,aAAa,CAAC,iBAAiB,CAAC,EAAE,GACrC,OAAO,CAAC,WAAW,CAAC;IAKvB;;OAEG;IACG,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,OAAO,CAAC,YAAY,CAAC;IAK3D;;;;OAIG;IACG,QAAQ,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC;IAInE;;;;;OAKG;YACW,MAAM;CAIrB"}
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Memory index handle with lazy initialization.
|
|
3
|
+
*/
|
|
4
|
+
import { planQuery, } from "@kernl-sdk/retrieval";
|
|
5
|
+
import { getAdapterCodecs } from "./codecs/index.js";
|
|
6
|
+
/**
|
|
7
|
+
* Domain-aware index handle for memory records with lazy initialization.
|
|
8
|
+
*
|
|
9
|
+
* - Wraps a SearchIndex and ensures the memory index is created before any operation.
|
|
10
|
+
* - Normalizes the idiosyncrasies of search adapters (capabilities, weird rules, ... - e.g. tpuf requires vector fields named
|
|
11
|
+
* literally 'vector' - dumb shit like this..)
|
|
12
|
+
*/
|
|
13
|
+
export class MemoryIndexHandle {
|
|
14
|
+
id;
|
|
15
|
+
index;
|
|
16
|
+
schema;
|
|
17
|
+
caps;
|
|
18
|
+
codecs;
|
|
19
|
+
providerOptions;
|
|
20
|
+
initPromise = null;
|
|
21
|
+
constructor(config) {
|
|
22
|
+
this.index = config.index;
|
|
23
|
+
this.id = config.indexId;
|
|
24
|
+
this.schema = config.schema;
|
|
25
|
+
this.caps = this.index.capabilities();
|
|
26
|
+
this.codecs = getAdapterCodecs(this.index.id);
|
|
27
|
+
this.providerOptions = config.providerOptions;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Ensure memory index exists (lazy initialization).
|
|
31
|
+
*
|
|
32
|
+
* Safe to call multiple times - initialization only runs once.
|
|
33
|
+
*/
|
|
34
|
+
async ensureInit() {
|
|
35
|
+
if (!this.initPromise) {
|
|
36
|
+
this.initPromise = this.createIndex().catch((err) => {
|
|
37
|
+
this.initPromise = null;
|
|
38
|
+
throw err;
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
await this.initPromise;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Create the memory index if it doesn't exist.
|
|
45
|
+
*/
|
|
46
|
+
async createIndex() {
|
|
47
|
+
try {
|
|
48
|
+
await this.index.createIndex({
|
|
49
|
+
id: this.id,
|
|
50
|
+
schema: this.codecs.schema.encode(this.schema),
|
|
51
|
+
providerOptions: this.providerOptions,
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
catch (err) {
|
|
55
|
+
// (TODO): we should probably enforce a stricter contract w/ tighter error types
|
|
56
|
+
//
|
|
57
|
+
// Ignore "already exists" errors
|
|
58
|
+
if (err.message?.includes("already exists") ||
|
|
59
|
+
err.message?.includes("AlreadyExists")) {
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
throw err;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Search for memory records matching the query.
|
|
67
|
+
*
|
|
68
|
+
* Adapts the query to backend capabilities, degrading gracefully
|
|
69
|
+
* when hybrid or multi-signal queries aren't supported.
|
|
70
|
+
*/
|
|
71
|
+
async query(input) {
|
|
72
|
+
const { input: planned } = planQuery(input, this.caps);
|
|
73
|
+
const q = this.codecs.query.encode(planned);
|
|
74
|
+
const handle = await this.handle();
|
|
75
|
+
const hits = await handle.query(q);
|
|
76
|
+
// decode hits back to IndexMemoryRecord format
|
|
77
|
+
return hits.map((hit) => ({
|
|
78
|
+
...hit,
|
|
79
|
+
document: hit.document
|
|
80
|
+
? this.codecs.doc.decode(hit.document)
|
|
81
|
+
: undefined,
|
|
82
|
+
}));
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Insert or update memory records in the index.
|
|
86
|
+
*/
|
|
87
|
+
async upsert(docs) {
|
|
88
|
+
const arr = Array.isArray(docs) ? docs : [docs];
|
|
89
|
+
const encoded = arr.map((doc) => this.codecs.doc.encode(doc));
|
|
90
|
+
const handle = await this.handle();
|
|
91
|
+
return handle.upsert(encoded);
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Partially update memory records without re-indexing vectors.
|
|
95
|
+
*
|
|
96
|
+
* Note: Patches don't include vector fields so we cast directly.
|
|
97
|
+
* Metadata field type mismatch (JSONObject vs FieldValue) is handled at runtime.
|
|
98
|
+
*/
|
|
99
|
+
async patch(patches) {
|
|
100
|
+
const handle = await this.handle();
|
|
101
|
+
return handle.patch(patches);
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Remove memory records from the index.
|
|
105
|
+
*/
|
|
106
|
+
async delete(ids) {
|
|
107
|
+
const handle = await this.handle();
|
|
108
|
+
return handle.delete(ids);
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Add a new field to the index schema.
|
|
112
|
+
*
|
|
113
|
+
* @throws Always throws - dynamic schema modification not supported
|
|
114
|
+
*/
|
|
115
|
+
async addField(_field, _schema) {
|
|
116
|
+
throw new Error("addField not supported for MemoryIndexHandle");
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Get an initialized underlying index handle.
|
|
120
|
+
*
|
|
121
|
+
* Returns a handle typed for UnknownDocument since we encode/decode
|
|
122
|
+
* through the adapter codecs for backend-specific field mapping.
|
|
123
|
+
*/
|
|
124
|
+
async handle() {
|
|
125
|
+
await this.ensureInit();
|
|
126
|
+
return this.index.index(this.id);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Memory module.
|
|
3
|
+
*/
|
|
4
|
+
export { Memory } from "./memory.js";
|
|
5
|
+
export { MemoryByteEncoder } from "./encoder.js";
|
|
6
|
+
export { buildMemoryIndexSchema } from "./schema.js";
|
|
7
|
+
export { MemoryIndexHandle } from "./handle.js";
|
|
8
|
+
export type { MemoryIndexHandleConfig } from "./handle.js";
|
|
9
|
+
export type { TextByte, ImageByte, AudioByte, VideoByte, MemoryByte, IndexableByte, MemoryByteCodec, MemoryScope, MemoryKind, NewMemory, AgentMemoryCreate, MemoryConfig, MemoryReindexParams, MemoryRecord, MemoryRecordUpdate, MemoryFilter, MemoryListOptions, MemorySearchQuery, IndexMemoryRecord, IndexMemoryRecordPatch, WorkingMemorySnapshot, ShortTermMemorySnapshot, } from "./types.js";
|
|
10
|
+
export type { MemoryStore } from "./store.js";
|
|
11
|
+
export type { MemoryIndexBase, MemorySearchIndex, MemoryGraphIndex, MemoryArchiveIndex, GraphTraversalQuery, GraphTraversalResult, ArchiveQuery, ArchiveResult, } from "./indexes.js";
|
|
12
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/memory/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAC;AAC9C,OAAO,EAAE,sBAAsB,EAAE,MAAM,UAAU,CAAC;AAClD,OAAO,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAC7C,YAAY,EAAE,uBAAuB,EAAE,MAAM,UAAU,CAAC;AAExD,YAAY,EAEV,QAAQ,EACR,SAAS,EACT,SAAS,EACT,SAAS,EACT,UAAU,EACV,aAAa,EACb,eAAe,EAEf,WAAW,EACX,UAAU,EACV,SAAS,EACT,iBAAiB,EACjB,YAAY,EACZ,mBAAmB,EACnB,YAAY,EACZ,kBAAkB,EAClB,YAAY,EACZ,iBAAiB,EACjB,iBAAiB,EACjB,iBAAiB,EACjB,sBAAsB,EACtB,qBAAqB,EACrB,uBAAuB,GACxB,MAAM,SAAS,CAAC;AAEjB,YAAY,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAE3C,YAAY,EACV,eAAe,EACf,iBAAiB,EACjB,gBAAgB,EAChB,kBAAkB,EAClB,mBAAmB,EACnB,oBAAoB,EACpB,YAAY,EACZ,aAAa,GACd,MAAM,WAAW,CAAC"}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Memory index interfaces.
|
|
3
|
+
*
|
|
4
|
+
* Indexes are projections of the primary store (DB) that enable
|
|
5
|
+
* specialized query patterns (vector search, graph traversal, archival).
|
|
6
|
+
*/
|
|
7
|
+
import type { SearchHit } from "@kernl-sdk/retrieval";
|
|
8
|
+
import type { MemoryRecord, MemoryRecordUpdate, MemorySearchQuery, IndexMemoryRecord } from "./types.js";
|
|
9
|
+
/**
|
|
10
|
+
* Base interface for memory indexes.
|
|
11
|
+
*
|
|
12
|
+
* All indexes share common lifecycle operations (index, patch, delete)
|
|
13
|
+
* but differ in their query interface.
|
|
14
|
+
*/
|
|
15
|
+
export interface MemoryIndexBase<TQuery, TResult> {
|
|
16
|
+
readonly id: string;
|
|
17
|
+
/**
|
|
18
|
+
* Query the index.
|
|
19
|
+
*/
|
|
20
|
+
query(query: TQuery): Promise<TResult>;
|
|
21
|
+
/**
|
|
22
|
+
* Index one or more memory records (idempotent upsert).
|
|
23
|
+
*/
|
|
24
|
+
index(memories: MemoryRecord | MemoryRecord[]): Promise<void>;
|
|
25
|
+
/**
|
|
26
|
+
* Partially update one or more records' projections.
|
|
27
|
+
*/
|
|
28
|
+
update(updates: MemoryRecordUpdate | MemoryRecordUpdate[]): Promise<void>;
|
|
29
|
+
/**
|
|
30
|
+
* Remove one or more records from this index (DB row remains).
|
|
31
|
+
*/
|
|
32
|
+
delete(ids: string | string[]): Promise<void>;
|
|
33
|
+
/**
|
|
34
|
+
* Index warming (optional).
|
|
35
|
+
*/
|
|
36
|
+
warm(index: string): Promise<void>;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Memory search index - vector/semantic search over memories.
|
|
40
|
+
*/
|
|
41
|
+
export interface MemorySearchIndex extends MemoryIndexBase<MemorySearchQuery, SearchHit<IndexMemoryRecord>[]> {
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Graph traversal query (stub).
|
|
45
|
+
*/
|
|
46
|
+
export interface GraphTraversalQuery {
|
|
47
|
+
depth?: number;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Graph traversal result (stub).
|
|
51
|
+
*/
|
|
52
|
+
export interface GraphTraversalResult {
|
|
53
|
+
nodes: Array<{
|
|
54
|
+
id: string;
|
|
55
|
+
record?: MemoryRecord;
|
|
56
|
+
}>;
|
|
57
|
+
edges: Array<{
|
|
58
|
+
from: string;
|
|
59
|
+
to: string;
|
|
60
|
+
relation: string;
|
|
61
|
+
}>;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Memory graph index - relationship/graph traversal over memories (stub).
|
|
65
|
+
*/
|
|
66
|
+
export interface MemoryGraphIndex extends MemoryIndexBase<GraphTraversalQuery, GraphTraversalResult> {
|
|
67
|
+
/**
|
|
68
|
+
* Explicit traversal API (alias for query).
|
|
69
|
+
*/
|
|
70
|
+
traverse(query: GraphTraversalQuery): Promise<GraphTraversalResult>;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Archive query (stub).
|
|
74
|
+
*/
|
|
75
|
+
export interface ArchiveQuery {
|
|
76
|
+
before?: number;
|
|
77
|
+
collections?: string[];
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Archive result (stub).
|
|
81
|
+
*/
|
|
82
|
+
export interface ArchiveResult {
|
|
83
|
+
id: string;
|
|
84
|
+
uri: string;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Memory archive index - cold storage/archival backend (stub).
|
|
88
|
+
*/
|
|
89
|
+
export interface MemoryArchiveIndex extends MemoryIndexBase<ArchiveQuery, ArchiveResult[]> {
|
|
90
|
+
}
|
|
91
|
+
//# sourceMappingURL=indexes.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"indexes.d.ts","sourceRoot":"","sources":["../../src/memory/indexes.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAEtD,OAAO,KAAK,EACV,YAAY,EACZ,kBAAkB,EAClB,iBAAiB,EACjB,iBAAiB,EAClB,MAAM,SAAS,CAAC;AAEjB;;;;;GAKG;AACH,MAAM,WAAW,eAAe,CAAC,MAAM,EAAE,OAAO;IAC9C,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAqD;IAExE;;OAEG;IACH,KAAK,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;IAEvC;;OAEG;IACH,KAAK,CAAC,QAAQ,EAAE,YAAY,GAAG,YAAY,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAE9D;;OAEG;IACH,MAAM,CAAC,OAAO,EAAE,kBAAkB,GAAG,kBAAkB,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAE1E;;OAEG;IACH,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAE9C;;OAEG;IACH,IAAI,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACpC;AAED;;GAEG;AACH,MAAM,WAAW,iBACf,SAAQ,eAAe,CAAC,iBAAiB,EAAE,SAAS,CAAC,iBAAiB,CAAC,EAAE,CAAC;CAAG;AAE/E;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAElC,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED;;GAEG;AACH,MAAM,WAAW,oBAAoB;IAEnC,KAAK,EAAE,KAAK,CAAC;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,YAAY,CAAA;KAAE,CAAC,CAAC;IACpD,KAAK,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,EAAE,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;CAC9D;AAED;;GAEG;AACH,MAAM,WAAW,gBACf,SAAQ,eAAe,CAAC,mBAAmB,EAAE,oBAAoB,CAAC;IAClE;;OAEG;IACH,QAAQ,CAAC,KAAK,EAAE,mBAAmB,GAAG,OAAO,CAAC,oBAAoB,CAAC,CAAC;CACrE;AAED;;GAEG;AACH,MAAM,WAAW,YAAY;IAE3B,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,WAAW,CAAC,EAAE,MAAM,EAAE,CAAC;CACxB;AAED;;GAEG;AACH,MAAM,WAAW,aAAa;IAE5B,EAAE,EAAE,MAAM,CAAC;IACX,GAAG,EAAE,MAAM,CAAC;CACb;AAED;;GAEG;AACH,MAAM,WAAW,kBACf,SAAQ,eAAe,CAAC,YAAY,EAAE,aAAa,EAAE,CAAC;CAAG"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import type { SearchHit } from "@kernl-sdk/retrieval";
|
|
2
|
+
import type { NewMemory, MemoryRecord, MemoryRecordUpdate, MemoryScope, MemoryConfig, MemorySearchQuery, IndexMemoryRecord, WorkingMemorySnapshot, ShortTermMemorySnapshot, MemoryReindexParams } from "./types.js";
|
|
3
|
+
/**
|
|
4
|
+
* Memory is the primary memory abstraction for agents.
|
|
5
|
+
*
|
|
6
|
+
* Sits above storage/index layers + owns cognitive policy, eviction/TTL, consolidation.
|
|
7
|
+
*
|
|
8
|
+
* - L1 / wmem: active working set exposed to the model
|
|
9
|
+
* - L2 / smem: bounded recent context with a TTL
|
|
10
|
+
* - L3 / lmem: durable, structured long-term store
|
|
11
|
+
*
|
|
12
|
+
* Delegates persistence to storage adapters and optional indexes as
|
|
13
|
+
* _projections_ of the primary memory store.
|
|
14
|
+
*/
|
|
15
|
+
export declare class Memory {
|
|
16
|
+
private readonly store;
|
|
17
|
+
private readonly _search;
|
|
18
|
+
private readonly encoder;
|
|
19
|
+
private readonly rcodec;
|
|
20
|
+
constructor(config: MemoryConfig);
|
|
21
|
+
/**
|
|
22
|
+
* Create a new memory record.
|
|
23
|
+
* Writes to primary store first, then indexes if configured.
|
|
24
|
+
*/
|
|
25
|
+
create(memory: NewMemory): Promise<MemoryRecord>;
|
|
26
|
+
/**
|
|
27
|
+
* Update an existing memory record.
|
|
28
|
+
* Updates primary store, then re-indexes or patches search index.
|
|
29
|
+
*/
|
|
30
|
+
update(update: MemoryRecordUpdate): Promise<MemoryRecord>;
|
|
31
|
+
/**
|
|
32
|
+
* Semantic/metadata search across memories.
|
|
33
|
+
*
|
|
34
|
+
* Sends rich query with both text and vector - the index handle
|
|
35
|
+
* adapts based on backend capabilities (e.g. drops text for pgvector).
|
|
36
|
+
*/
|
|
37
|
+
search(q: MemorySearchQuery): Promise<SearchHit<IndexMemoryRecord>[]>;
|
|
38
|
+
/**
|
|
39
|
+
* Repair indexing for a memory without modifying the DB row.
|
|
40
|
+
*/
|
|
41
|
+
reindex(params: MemoryReindexParams): Promise<void>;
|
|
42
|
+
/**
|
|
43
|
+
* Load working memory (L1) - wmem-pinned memories for the scope.
|
|
44
|
+
*/
|
|
45
|
+
loadWorkingMemory(scope: MemoryScope): Promise<WorkingMemorySnapshot>;
|
|
46
|
+
/**
|
|
47
|
+
* Load short-term memory (L2) - active smem for the scope.
|
|
48
|
+
*/
|
|
49
|
+
loadShortTermMemory(scope: MemoryScope): Promise<ShortTermMemorySnapshot>;
|
|
50
|
+
}
|
|
51
|
+
//# sourceMappingURL=memory.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"memory.d.ts","sourceRoot":"","sources":["../../src/memory/memory.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAe,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAInE,OAAO,KAAK,EACV,SAAS,EACT,YAAY,EACZ,kBAAkB,EAClB,WAAW,EACX,YAAY,EACZ,iBAAiB,EAEjB,iBAAiB,EACjB,qBAAqB,EACrB,uBAAuB,EACvB,mBAAmB,EACpB,MAAM,SAAS,CAAC;AAGjB;;;;;;;;;;;GAWG;AACH,qBAAa,MAAM;IACjB,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAc;IACpC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAwC;IAEhE,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAkB;IAC1C,OAAO,CAAC,QAAQ,CAAC,MAAM,CAA8C;gBAEzD,MAAM,EAAE,YAAY;IAShC;;;OAGG;IACG,MAAM,CAAC,MAAM,EAAE,SAAS,GAAG,OAAO,CAAC,YAAY,CAAC;IAYtD;;;OAGG;IACG,MAAM,CAAC,MAAM,EAAE,kBAAkB,GAAG,OAAO,CAAC,YAAY,CAAC;IAe/D;;;;;OAKG;IACG,MAAM,CAAC,CAAC,EAAE,iBAAiB,GAAG,OAAO,CAAC,SAAS,CAAC,iBAAiB,CAAC,EAAE,CAAC;IAc3E;;OAEG;IACG,OAAO,CAAC,MAAM,EAAE,mBAAmB,GAAG,OAAO,CAAC,IAAI,CAAC;IAgBzD;;OAEG;IACG,iBAAiB,CAAC,KAAK,EAAE,WAAW,GAAG,OAAO,CAAC,qBAAqB,CAAC;IAO3E;;OAEG;IACG,mBAAmB,CACvB,KAAK,EAAE,WAAW,GACjB,OAAO,CAAC,uBAAuB,CAAC;CAMpC"}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { MEMORY_FILTER, PATCH_CODEC, recordCodec } from "./codecs/index.js";
|
|
2
|
+
/**
|
|
3
|
+
* Memory is the primary memory abstraction for agents.
|
|
4
|
+
*
|
|
5
|
+
* Sits above storage/index layers + owns cognitive policy, eviction/TTL, consolidation.
|
|
6
|
+
*
|
|
7
|
+
* - L1 / wmem: active working set exposed to the model
|
|
8
|
+
* - L2 / smem: bounded recent context with a TTL
|
|
9
|
+
* - L3 / lmem: durable, structured long-term store
|
|
10
|
+
*
|
|
11
|
+
* Delegates persistence to storage adapters and optional indexes as
|
|
12
|
+
* _projections_ of the primary memory store.
|
|
13
|
+
*/
|
|
14
|
+
export class Memory {
|
|
15
|
+
store;
|
|
16
|
+
_search;
|
|
17
|
+
encoder;
|
|
18
|
+
rcodec;
|
|
19
|
+
constructor(config) {
|
|
20
|
+
this.store = config.store;
|
|
21
|
+
this._search = config.search ?? null;
|
|
22
|
+
// TODO: default encoder using text-embedding-3-small
|
|
23
|
+
this.encoder = config.encoder;
|
|
24
|
+
this.rcodec = recordCodec(config.encoder);
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Create a new memory record.
|
|
28
|
+
* Writes to primary store first, then indexes if configured.
|
|
29
|
+
*/
|
|
30
|
+
async create(memory) {
|
|
31
|
+
const record = await this.store.create(memory);
|
|
32
|
+
// index into search if avail
|
|
33
|
+
if (this._search) {
|
|
34
|
+
const indexed = await this.rcodec.encode(record);
|
|
35
|
+
await this._search.upsert(indexed);
|
|
36
|
+
}
|
|
37
|
+
return record;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Update an existing memory record.
|
|
41
|
+
* Updates primary store, then re-indexes or patches search index.
|
|
42
|
+
*/
|
|
43
|
+
async update(update) {
|
|
44
|
+
const record = await this.store.update(update.id, update);
|
|
45
|
+
if (!this._search)
|
|
46
|
+
return record;
|
|
47
|
+
if (update.content) {
|
|
48
|
+
const indexed = await this.rcodec.encode(record); // content changed → full re-index with new embeddings
|
|
49
|
+
await this._search.upsert(indexed);
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
const patch = PATCH_CODEC.encode(update); // metadata only → cheap patch
|
|
53
|
+
await this._search.patch(patch);
|
|
54
|
+
}
|
|
55
|
+
return record;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Semantic/metadata search across memories.
|
|
59
|
+
*
|
|
60
|
+
* Sends rich query with both text and vector - the index handle
|
|
61
|
+
* adapts based on backend capabilities (e.g. drops text for pgvector).
|
|
62
|
+
*/
|
|
63
|
+
async search(q) {
|
|
64
|
+
if (!this._search) {
|
|
65
|
+
throw new Error("search index not configured");
|
|
66
|
+
}
|
|
67
|
+
const tvec = await this.encoder.embed(q.query);
|
|
68
|
+
return this._search.query({
|
|
69
|
+
query: [{ text: q.query, tvec }],
|
|
70
|
+
filter: q.filter ? MEMORY_FILTER.encode(q.filter) : undefined,
|
|
71
|
+
topK: q.limit ?? 20,
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Repair indexing for a memory without modifying the DB row.
|
|
76
|
+
*/
|
|
77
|
+
async reindex(params) {
|
|
78
|
+
const record = await this.store.get(params.id);
|
|
79
|
+
if (!record) {
|
|
80
|
+
throw new Error(`memory not found: ${params.id}`);
|
|
81
|
+
}
|
|
82
|
+
const indexes = params.indexes ?? ["search", "graph", "archive"];
|
|
83
|
+
if (indexes.includes("search") && this._search) {
|
|
84
|
+
const indexed = await this.rcodec.encode(record);
|
|
85
|
+
await this._search.upsert(indexed);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
/* --- (TODO): unclear what the shape of these should be.. --- */
|
|
89
|
+
/**
|
|
90
|
+
* Load working memory (L1) - wmem-pinned memories for the scope.
|
|
91
|
+
*/
|
|
92
|
+
async loadWorkingMemory(scope) {
|
|
93
|
+
const records = await this.store.list({
|
|
94
|
+
filter: { scope, wmem: true },
|
|
95
|
+
});
|
|
96
|
+
return { scope, records };
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Load short-term memory (L2) - active smem for the scope.
|
|
100
|
+
*/
|
|
101
|
+
async loadShortTermMemory(scope) {
|
|
102
|
+
const records = await this.store.list({
|
|
103
|
+
filter: { scope, smem: true },
|
|
104
|
+
});
|
|
105
|
+
return { scope, records };
|
|
106
|
+
}
|
|
107
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Memory index schema builder.
|
|
3
|
+
*/
|
|
4
|
+
import type { FieldSchema } from "@kernl-sdk/retrieval";
|
|
5
|
+
/**
|
|
6
|
+
* Options for building memory index schema.
|
|
7
|
+
*/
|
|
8
|
+
export interface MemoryIndexSchemaOptions {
|
|
9
|
+
/**
|
|
10
|
+
* Vector dimensions for embeddings.
|
|
11
|
+
* @default 1536 (OpenAI text-embedding-3-small)
|
|
12
|
+
*/
|
|
13
|
+
dimensions?: number;
|
|
14
|
+
/**
|
|
15
|
+
* Similarity metric for vector search.
|
|
16
|
+
* @default "cosine"
|
|
17
|
+
*/
|
|
18
|
+
similarity?: "cosine" | "euclidean" | "dot_product";
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Build a canonical memory index schema for vector search.
|
|
22
|
+
*
|
|
23
|
+
* Returns a schema Record that can be used with SearchIndex.createIndex().
|
|
24
|
+
*
|
|
25
|
+
* Schema includes all fields from IndexMemoryRecord:
|
|
26
|
+
* - id: primary key
|
|
27
|
+
* - namespace, entityId, agentId: scope fields (filterable, nullable)
|
|
28
|
+
* - kind, collection: memory attributes (filterable)
|
|
29
|
+
* - timestamp, createdAt, updatedAt: timestamps (filterable + sortable)
|
|
30
|
+
* - text: content text (full-text search)
|
|
31
|
+
* - tvec, ivec, avec, vvec: vector embeddings for text/image/audio/video
|
|
32
|
+
* - metadata: structured metadata (object)
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* ```ts
|
|
36
|
+
* const schema = buildMemoryIndexSchema({ dimensions: 1536 });
|
|
37
|
+
* const handle = new MemoryIndexHandle({ index: vector, indexId: "kernl_memories", schema });
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
40
|
+
export declare function buildMemoryIndexSchema(options?: MemoryIndexSchemaOptions): Record<string, FieldSchema>;
|
|
41
|
+
//# sourceMappingURL=schema.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../src/memory/schema.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAExD;;GAEG;AACH,MAAM,WAAW,wBAAwB;IACvC;;;OAGG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IAEpB;;;OAGG;IACH,UAAU,CAAC,EAAE,QAAQ,GAAG,WAAW,GAAG,aAAa,CAAC;CACrD;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,sBAAsB,CACpC,OAAO,GAAE,wBAA6B,GACrC,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,CAgG7B"}
|