@workglow/knowledge-base 0.1.2 → 0.2.0
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/README.md +166 -0
- package/dist/browser.js +321 -25
- package/dist/browser.js.map +15 -12
- package/dist/bun.js +321 -25
- package/dist/bun.js.map +15 -12
- package/dist/chunk/ChunkVectorStorageSchema.d.ts +1 -1
- package/dist/chunk/ChunkVectorStorageSchema.d.ts.map +1 -1
- package/dist/common.d.ts +3 -0
- package/dist/common.d.ts.map +1 -1
- package/dist/document/Document.d.ts.map +1 -1
- package/dist/document/DocumentNode.d.ts +1 -1
- package/dist/document/DocumentNode.d.ts.map +1 -1
- package/dist/document/DocumentStorageSchema.d.ts +2 -1
- package/dist/document/DocumentStorageSchema.d.ts.map +1 -1
- package/dist/document/StructuralParser.d.ts +1 -1
- package/dist/document/StructuralParser.d.ts.map +1 -1
- package/dist/knowledge-base/KnowledgeBase.d.ts +2 -0
- package/dist/knowledge-base/KnowledgeBase.d.ts.map +1 -1
- package/dist/knowledge-base/KnowledgeBaseRegistry.d.ts +17 -1
- package/dist/knowledge-base/KnowledgeBaseRegistry.d.ts.map +1 -1
- package/dist/knowledge-base/KnowledgeBaseRepository.d.ts +5 -3
- package/dist/knowledge-base/KnowledgeBaseRepository.d.ts.map +1 -1
- package/dist/knowledge-base/KnowledgeBaseSchema.d.ts +4 -0
- package/dist/knowledge-base/KnowledgeBaseSchema.d.ts.map +1 -1
- package/dist/knowledge-base/ScopedTabularStorage.d.ts +46 -0
- package/dist/knowledge-base/ScopedTabularStorage.d.ts.map +1 -0
- package/dist/knowledge-base/ScopedVectorStorage.d.ts +27 -0
- package/dist/knowledge-base/ScopedVectorStorage.d.ts.map +1 -0
- package/dist/knowledge-base/SharedTableSchemas.d.ts +93 -0
- package/dist/knowledge-base/SharedTableSchemas.d.ts.map +1 -0
- package/dist/node.js +321 -25
- package/dist/node.js.map +15 -12
- package/package.json +10 -5
|
@@ -26,11 +26,27 @@ export declare function getGlobalKnowledgeBaseRepository(): KnowledgeBaseReposit
|
|
|
26
26
|
* Sets the global knowledge base repository instance
|
|
27
27
|
*/
|
|
28
28
|
export declare function setGlobalKnowledgeBaseRepository(repository: KnowledgeBaseRepository): void;
|
|
29
|
+
export interface RegisterKnowledgeBaseOptions {
|
|
30
|
+
/** When true, record uses shared table names instead of per-KB table names. */
|
|
31
|
+
readonly sharedTables?: boolean;
|
|
32
|
+
}
|
|
29
33
|
/**
|
|
30
34
|
* Registers a knowledge base globally by ID.
|
|
31
35
|
* Adds to both the live Map and the persistent repository.
|
|
36
|
+
* Serialized per-ID to prevent Map/repo divergence on concurrent calls.
|
|
32
37
|
*/
|
|
33
|
-
export declare function registerKnowledgeBase(id: string, kb: KnowledgeBase): Promise<void>;
|
|
38
|
+
export declare function registerKnowledgeBase(id: string, kb: KnowledgeBase, options?: RegisterKnowledgeBaseOptions): Promise<void>;
|
|
39
|
+
/**
|
|
40
|
+
* Unregisters a knowledge base by ID.
|
|
41
|
+
* Removes from both the persistent repository and the live Map.
|
|
42
|
+
* Serialized per-ID to prevent Map/repo divergence on concurrent calls.
|
|
43
|
+
*/
|
|
44
|
+
export declare function unregisterKnowledgeBase(id: string): Promise<void>;
|
|
45
|
+
/**
|
|
46
|
+
* Deregisters a knowledge base by ID.
|
|
47
|
+
* Removes from both the live Map and the persistent repository.
|
|
48
|
+
*/
|
|
49
|
+
export declare function deregisterKnowledgeBase(id: string): Promise<void>;
|
|
34
50
|
/**
|
|
35
51
|
* Gets a knowledge base by ID from the global registry
|
|
36
52
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"KnowledgeBaseRegistry.d.ts","sourceRoot":"","sources":["../../src/knowledge-base/KnowledgeBaseRegistry.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAUH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AACrD,OAAO,EAAE,uBAAuB,EAAE,MAAM,2BAA2B,CAAC;
|
|
1
|
+
{"version":3,"file":"KnowledgeBaseRegistry.d.ts","sourceRoot":"","sources":["../../src/knowledge-base/KnowledgeBaseRegistry.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAUH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AACrD,OAAO,EAAE,uBAAuB,EAAE,MAAM,2BAA2B,CAAC;AAKpE;;;GAGG;AACH,eAAO,MAAM,eAAe,mEAC+C,CAAC;AAE5E;;GAEG;AACH,eAAO,MAAM,yBAAyB,gEAErC,CAAC;AAgBF;;GAEG;AACH,wBAAgB,uBAAuB,IAAI,GAAG,CAAC,MAAM,EAAE,aAAa,CAAC,CAEpE;AAED;;GAEG;AACH,wBAAgB,gCAAgC,IAAI,uBAAuB,CAE1E;AAED;;GAEG;AACH,wBAAgB,gCAAgC,CAAC,UAAU,EAAE,uBAAuB,GAAG,IAAI,CAE1F;AAED,MAAM,WAAW,4BAA4B;IAC3C,+EAA+E;IAC/E,QAAQ,CAAC,YAAY,CAAC,EAAE,OAAO,CAAC;CACjC;AA0BD;;;;GAIG;AAEH,wBAAgB,qBAAqB,CACnC,EAAE,EAAE,MAAM,EACV,EAAE,EAAE,aAAa,EACjB,OAAO,CAAC,EAAE,4BAA4B,GACrC,OAAO,CAAC,IAAI,CAAC,CA2Bf;AAED;;;;GAIG;AACH,wBAAgB,uBAAuB,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAQjE;AAED;;;GAGG;AACH,wBAAsB,uBAAuB,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAOvE;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,EAAE,EAAE,MAAM,GAAG,aAAa,GAAG,SAAS,CAEtE"}
|
|
@@ -3,9 +3,11 @@
|
|
|
3
3
|
* Copyright 2025 Steven Roussey <sroussey@gmail.com>
|
|
4
4
|
* SPDX-License-Identifier: Apache-2.0
|
|
5
5
|
*/
|
|
6
|
-
import {
|
|
7
|
-
import { EventEmitter
|
|
8
|
-
import
|
|
6
|
+
import type { ITabularStorage } from "@workglow/storage";
|
|
7
|
+
import { EventEmitter } from "@workglow/util";
|
|
8
|
+
import type { EventParameters } from "@workglow/util";
|
|
9
|
+
import { KnowledgeBasePrimaryKeyNames, KnowledgeBaseRecordSchema } from "./KnowledgeBaseSchema";
|
|
10
|
+
import type { KnowledgeBaseRecord } from "./KnowledgeBaseSchema";
|
|
9
11
|
/**
|
|
10
12
|
* Events that can be emitted by the KnowledgeBaseRepository
|
|
11
13
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"KnowledgeBaseRepository.d.ts","sourceRoot":"","sources":["../../src/knowledge-base/KnowledgeBaseRepository.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"KnowledgeBaseRepository.d.ts","sourceRoot":"","sources":["../../src/knowledge-base/KnowledgeBaseRepository.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACzD,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAEtD,OAAO,EAAE,4BAA4B,EAAE,yBAAyB,EAAE,MAAM,uBAAuB,CAAC;AAChG,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAEjE;;GAEG;AAEH,MAAM,MAAM,2BAA2B,GAAG;IACxC,oBAAoB,EAAE,CAAC,MAAM,EAAE,mBAAmB,KAAK,IAAI,CAAC;IAC5D,sBAAsB,EAAE,CAAC,MAAM,EAAE,mBAAmB,KAAK,IAAI,CAAC;IAC9D,sBAAsB,EAAE,CAAC,MAAM,EAAE,mBAAmB,KAAK,IAAI,CAAC;CAC/D,CAAC;AAEF,MAAM,MAAM,mBAAmB,GAA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K,EAAE,MAAM,GAAG,OAAO,CAAC,mBAAmB,GAAG,SAAS,CAAC,CAI9E;IAED;;OAEG;IACG,YAAY,IAAI,OAAO,CAAC,mBAAmB,EAAE,CAAC,CAInD;IAED;;OAEG;IACG,IAAI,IAAI,OAAO,CAAC,MAAM,CAAC,CAE5B;CACF"}
|
|
@@ -47,4 +47,8 @@ export declare function knowledgeBaseTableNames(kbId: string): {
|
|
|
47
47
|
readonly documentTable: string;
|
|
48
48
|
readonly chunkTable: string;
|
|
49
49
|
};
|
|
50
|
+
/**
|
|
51
|
+
* Checks whether a KnowledgeBaseRecord uses shared-table mode.
|
|
52
|
+
*/
|
|
53
|
+
export declare function isSharedTableMode(record: KnowledgeBaseRecord): boolean;
|
|
50
54
|
//# sourceMappingURL=KnowledgeBaseSchema.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"KnowledgeBaseSchema.d.ts","sourceRoot":"","sources":["../../src/knowledge-base/KnowledgeBaseSchema.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAwB,UAAU,EAAE,MAAM,uBAAuB,CAAC;
|
|
1
|
+
{"version":3,"file":"KnowledgeBaseSchema.d.ts","sourceRoot":"","sources":["../../src/knowledge-base/KnowledgeBaseSchema.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAwB,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAG9E;;GAEG;AACH,eAAO,MAAM,yBAAyB;mBAC9B,QAAQ;;iBAEZ,KAAK;qBAAI,IAAI,EAAE,QAAQ;;iBACvB,KAAK;qBAAI,IAAI,EAAE,QAAQ;;iBACvB,WAAW;qBAAI,IAAI,EAAE,QAAQ;;iBAC7B,iBAAiB;qBAAI,IAAI,EAAE,SAAS;;iBACpC,cAAc;qBAAI,IAAI,EAAE,QAAQ;;iBAChC,WAAW;qBAAI,IAAI,EAAE,QAAQ;;iBAC7B,UAAU;qBAAI,IAAI,EAAE,QAAQ;;iBAC5B,UAAU;qBAAI,IAAI,EAAE,QAAQ;;;;;CAaS,CAAC;AAE1C,MAAM,MAAM,mBAAmB,GAAG,UAAU,CAAC,OAAO,yBAAyB,CAAC,CAAC;AAC/E,eAAO,MAAM,4BAA4B,YAAI,OAAO,CAAU,CAAC;AAE/D;;GAEG;AACH,wBAAgB,uBAAuB,CAAC,IAAI,EAAE,MAAM,GAAG;IACrD,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;IAC/B,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;CAC7B,CAMA;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,mBAAmB,GAAG,OAAO,CAItE"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2025 Steven Roussey <sroussey@gmail.com>
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
import type { AnyTabularStorage, DeleteSearchCriteria, ITabularStorage, QueryOptions, SearchCriteria, TabularChangePayload, TabularEventListener, TabularEventListeners, TabularEventName, TabularEventParameters, TabularSubscribeOptions } from "@workglow/storage";
|
|
7
|
+
import { EventEmitter } from "@workglow/util";
|
|
8
|
+
import type { DataPortSchemaObject } from "@workglow/util/schema";
|
|
9
|
+
/**
|
|
10
|
+
* Wrapper implementing `ITabularStorage` that delegates to an inner shared
|
|
11
|
+
* storage instance, injecting `kb_id` on writes and filtering by `kb_id` on
|
|
12
|
+
* reads. The outer interface does not include `kb_id` — it is transparent to
|
|
13
|
+
* the `KnowledgeBase` class.
|
|
14
|
+
*/
|
|
15
|
+
export declare class ScopedTabularStorage<Schema extends DataPortSchemaObject, PrimaryKeyNames extends ReadonlyArray<keyof Schema["properties"]>, Entity = any, PrimaryKey = any, InsertType = any> implements ITabularStorage<Schema, PrimaryKeyNames, Entity, PrimaryKey, InsertType> {
|
|
16
|
+
protected readonly inner: AnyTabularStorage;
|
|
17
|
+
protected readonly kbId: string;
|
|
18
|
+
protected readonly events: EventEmitter<TabularEventListeners<PrimaryKey, Entity>>;
|
|
19
|
+
constructor(inner: AnyTabularStorage, kbId: string);
|
|
20
|
+
private inject;
|
|
21
|
+
private strip;
|
|
22
|
+
private stripArray;
|
|
23
|
+
put(value: InsertType): Promise<Entity>;
|
|
24
|
+
putBulk(values: InsertType[]): Promise<Entity[]>;
|
|
25
|
+
get(key: PrimaryKey): Promise<Entity | undefined>;
|
|
26
|
+
delete(key: PrimaryKey | Entity): Promise<void>;
|
|
27
|
+
getAll(options?: QueryOptions<Entity>): Promise<Entity[] | undefined>;
|
|
28
|
+
deleteAll(): Promise<void>;
|
|
29
|
+
size(): Promise<number>;
|
|
30
|
+
query(criteria: SearchCriteria<Entity>, options?: QueryOptions<Entity>): Promise<Entity[] | undefined>;
|
|
31
|
+
deleteSearch(criteria: DeleteSearchCriteria<Entity>): Promise<void>;
|
|
32
|
+
getBulk(offset: number, limit: number): Promise<Entity[] | undefined>;
|
|
33
|
+
records(pageSize?: number): AsyncGenerator<Entity, void, undefined>;
|
|
34
|
+
pages(pageSize?: number): AsyncGenerator<Entity[], void, undefined>;
|
|
35
|
+
on<Event extends TabularEventName>(name: Event, fn: TabularEventListener<Event, PrimaryKey, Entity>): void;
|
|
36
|
+
off<Event extends TabularEventName>(name: Event, fn: TabularEventListener<Event, PrimaryKey, Entity>): void;
|
|
37
|
+
emit<Event extends TabularEventName>(name: Event, ...args: TabularEventParameters<Event, PrimaryKey, Entity>): void;
|
|
38
|
+
once<Event extends TabularEventName>(name: Event, fn: TabularEventListener<Event, PrimaryKey, Entity>): void;
|
|
39
|
+
waitOn<Event extends TabularEventName>(name: Event): Promise<TabularEventParameters<Event, PrimaryKey, Entity>>;
|
|
40
|
+
subscribeToChanges(callback: (change: TabularChangePayload<Entity>) => void, options?: TabularSubscribeOptions): () => void;
|
|
41
|
+
setupDatabase(): Promise<void>;
|
|
42
|
+
destroy(): void;
|
|
43
|
+
[Symbol.dispose](): void;
|
|
44
|
+
[Symbol.asyncDispose](): Promise<void>;
|
|
45
|
+
}
|
|
46
|
+
//# sourceMappingURL=ScopedTabularStorage.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ScopedTabularStorage.d.ts","sourceRoot":"","sources":["../../src/knowledge-base/ScopedTabularStorage.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EACV,iBAAiB,EACjB,oBAAoB,EACpB,eAAe,EACf,YAAY,EACZ,cAAc,EACd,oBAAoB,EACpB,oBAAoB,EACpB,qBAAqB,EACrB,gBAAgB,EAChB,sBAAsB,EACtB,uBAAuB,EACxB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,uBAAuB,CAAC;AAElE;;;;;GAKG;AACH,qBAAa,oBAAoB,CAC/B,MAAM,SAAS,oBAAoB,EACnC,eAAe,SAAS,aAAa,CAAC,MAAM,MAAM,CAAC,YAAY,CAAC,CAAC,EACjE,MAAM,GAAG,GAAG,EACZ,UAAU,GAAG,GAAG,EAChB,UAAU,GAAG,GAAG,CAChB,YAAW,eAAe,CAAC,MAAM,EAAE,eAAe,EAAE,MAAM,EAAE,UAAU,EAAE,UAAU,CAAC;IACnF,SAAS,CAAC,QAAQ,CAAC,KAAK,EAAE,iBAAiB,CAAC;IAC5C,SAAS,CAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAChC,SAAS,CAAC,QAAQ,CAAC,MAAM,0DAAiE;IAE1F,YAAY,KAAK,EAAE,iBAAiB,EAAE,IAAI,EAAE,MAAM,EAGjD;IAED,OAAO,CAAC,MAAM;IAId,OAAO,CAAC,KAAK;IAMb,OAAO,CAAC,UAAU;IAKZ,GAAG,CAAC,KAAK,EAAE,UAAU,GAAG,OAAO,CAAC,MAAM,CAAC,CAK5C;IAEK,OAAO,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AAE,KAAK,EACX,EAAE,EAAE,oBAAoB,CAAC,KAAK,EAAE,UAAU,EAAE,MAAM,CAAC,GAClD,IAAI,CAEN;IAED,IAAI,CAAC,KAAK,SAAS,gBAAgB,EACjC,IAAI,EAAE,KAAK,EACX,GAAG,IAAI,EAAE,sBAAsB,CAAC,KAAK,EAAE,UAAU,EAAE,MAAM,CAAC,GACzD,IAAI,CAEN;IAED,IAAI,CAAC,KAAK,SAAS,gBAAgB,EACjC,IAAI,EAAE,KAAK,EACX,EAAE,EAAE,oBAAoB,CAAC,KAAK,EAAE,UAAU,EAAE,MAAM,CAAC,GAClD,IAAI,CAEN;IAED,MAAM,CAAC,KAAK,SAAS,gBAAgB,EACnC,IAAI,EAAE,KAAK,GACV,OAAO,CAAC,sBAAsB,CAAC,KAAK,EAAE,UAAU,EAAE,MAAM,CAAC,CAAC,CAE5D;IAED,kBAAkB,CAChB,QAAQ,EAAE,CAAC,MAAM,EAAE,oBAAoB,CAAC,MAAM,CAAC,KAAK,IAAI,EACxD,OAAO,CAAC,EAAE,uBAAuB,GAChC,MAAM,IAAI,CAaZ;IAGK,aAAa,IAAI,OAAO,CAAC,IAAI,CAAC,CAEnC;IAED,OAAO,IAAI,IAAI,CAEd;IAED,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,IAAI,CAEvB;IAEK,CAAC,MAAM,CAAC,YAAY,CAAC,IAAI,OAAO,CAAC,IAAI,CAAC,CAE3C;CACF"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2025 Steven Roussey <sroussey@gmail.com>
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
import type { AnyVectorStorage, HybridSearchOptions, IVectorStorage, VectorSearchOptions } from "@workglow/storage";
|
|
7
|
+
import type { DataPortSchemaObject, TypedArray } from "@workglow/util/schema";
|
|
8
|
+
import { ScopedTabularStorage } from "./ScopedTabularStorage";
|
|
9
|
+
/**
|
|
10
|
+
* Wrapper extending `ScopedTabularStorage` that also implements `IVectorStorage`.
|
|
11
|
+
* Delegates vector search methods to the inner shared vector storage,
|
|
12
|
+
* post-filtering results by `kb_id`.
|
|
13
|
+
*/
|
|
14
|
+
export declare class ScopedVectorStorage<Metadata extends Record<string, unknown> | undefined, Schema extends DataPortSchemaObject, Entity = any, PrimaryKeyNames extends ReadonlyArray<keyof Schema["properties"]> = ReadonlyArray<keyof Schema["properties"]>> extends ScopedTabularStorage<Schema, PrimaryKeyNames, Entity> implements IVectorStorage<Metadata, Schema, Entity, PrimaryKeyNames> {
|
|
15
|
+
protected readonly inner: AnyVectorStorage;
|
|
16
|
+
private readonly overFetchMultiplier;
|
|
17
|
+
constructor(inner: AnyVectorStorage, kbId: string, overFetchMultiplier?: number);
|
|
18
|
+
getVectorDimensions(): number;
|
|
19
|
+
private filterAndStrip;
|
|
20
|
+
similaritySearch(query: TypedArray, options?: VectorSearchOptions<Metadata>): Promise<(Entity & {
|
|
21
|
+
score: number;
|
|
22
|
+
})[]>;
|
|
23
|
+
hybridSearch(query: TypedArray, options: HybridSearchOptions<Metadata>): Promise<(Entity & {
|
|
24
|
+
score: number;
|
|
25
|
+
})[]>;
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=ScopedVectorStorage.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ScopedVectorStorage.d.ts","sourceRoot":"","sources":["../../src/knowledge-base/ScopedVectorStorage.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EACV,gBAAgB,EAChB,mBAAmB,EACnB,cAAc,EACd,mBAAmB,EACpB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,KAAK,EAAE,oBAAoB,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAC9E,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAE9D;;;;GAIG;AACH,qBAAa,mBAAmB,CAC9B,QAAQ,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS,EACpD,MAAM,SAAS,oBAAoB,EACnC,MAAM,GAAG,GAAG,EACZ,eAAe,SAAS,aAAa,CAAC,MAAM,MAAM,CAAC,YAAY,CAAC,CAAC,GAAG,aAAa,CAC/E,MAAM,MAAM,CAAC,YAAY,CAAC,CAC3B,CAED,SAAQ,oBAAoB,CAAC,MAAM,EAAE,eAAe,EAAE,MAAM,CAC5D,YAAW,cAAc,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,eAAe,CAAC;IAEpE,mBAA4B,KAAK,EAAE,gBAAgB,CAAC;IACpD,OAAO,CAAC,QAAQ,CAAC,mBAAmB,CAAS;IAE7C,YAAY,KAAK,EAAE,gBAAgB,EAAE,IAAI,EAAE,MAAM,EAAE,mBAAmB,GAAE,MAAU,EAIjF;IAED,mBAAmB,IAAI,MAAM,CAE5B;IAED,OAAO,CAAC,cAAc;IAuBhB,gBAAgB,CACpB,KAAK,EAAE,UAAU,EACjB,OAAO,CAAC,EAAE,mBAAmB,CAAC,QAAQ,CAAC,GACtC,OAAO,CAAC,CAAC,MAAM,GAAG;QAAE,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC,EAAE,CAAC,CAQzC;IAEK,YAAY,CAChB,KAAK,EAAE,UAAU,EACjB,OAAO,EAAE,mBAAmB,CAAC,QAAQ,CAAC,GACrC,OAAO,CAAC,CAAC,MAAM,GAAG;QAAE,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC,EAAE,CAAC,CAczC;CACF"}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2025 Steven Roussey <sroussey@gmail.com>
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Default table names for shared-table mode.
|
|
8
|
+
*/
|
|
9
|
+
export declare const SHARED_DOCUMENT_TABLE = "shared_documents";
|
|
10
|
+
export declare const SHARED_CHUNK_TABLE = "shared_chunks";
|
|
11
|
+
/**
|
|
12
|
+
* Augmented document storage schema with kb_id column for shared-table mode.
|
|
13
|
+
*/
|
|
14
|
+
export declare const SharedDocumentStorageSchema: {
|
|
15
|
+
readonly type: "object";
|
|
16
|
+
readonly properties: {
|
|
17
|
+
readonly doc_id: {
|
|
18
|
+
readonly type: "string";
|
|
19
|
+
readonly "x-auto-generated": true;
|
|
20
|
+
readonly title: "Document ID";
|
|
21
|
+
readonly description: "Unique identifier for the document";
|
|
22
|
+
};
|
|
23
|
+
readonly kb_id: {
|
|
24
|
+
readonly type: "string";
|
|
25
|
+
readonly title: "Knowledge Base ID";
|
|
26
|
+
readonly description: "Owning knowledge base identifier";
|
|
27
|
+
};
|
|
28
|
+
readonly data: {
|
|
29
|
+
readonly type: "string";
|
|
30
|
+
readonly title: "Document Data";
|
|
31
|
+
readonly description: "JSON-serialized document";
|
|
32
|
+
};
|
|
33
|
+
readonly metadata: {
|
|
34
|
+
readonly type: "object";
|
|
35
|
+
readonly title: "Metadata";
|
|
36
|
+
readonly description: "Metadata of the document";
|
|
37
|
+
};
|
|
38
|
+
};
|
|
39
|
+
readonly required: readonly ["doc_id", "kb_id", "data"];
|
|
40
|
+
readonly additionalProperties: true;
|
|
41
|
+
};
|
|
42
|
+
/**
|
|
43
|
+
* Augmented chunk vector storage schema with kb_id column for shared-table mode.
|
|
44
|
+
*/
|
|
45
|
+
export declare const SharedChunkVectorStorageSchema: {
|
|
46
|
+
readonly type: "object";
|
|
47
|
+
readonly properties: {
|
|
48
|
+
readonly chunk_id: {
|
|
49
|
+
readonly type: "string";
|
|
50
|
+
readonly "x-auto-generated": true;
|
|
51
|
+
};
|
|
52
|
+
readonly kb_id: {
|
|
53
|
+
readonly type: "string";
|
|
54
|
+
};
|
|
55
|
+
readonly doc_id: {
|
|
56
|
+
readonly type: "string";
|
|
57
|
+
};
|
|
58
|
+
readonly vector: {
|
|
59
|
+
readonly type: "array";
|
|
60
|
+
readonly format: "TypedArray";
|
|
61
|
+
readonly title: "Typed Array";
|
|
62
|
+
readonly description: "A typed array (Float32Array, Int8Array, etc.)";
|
|
63
|
+
};
|
|
64
|
+
readonly metadata: {
|
|
65
|
+
readonly type: "object";
|
|
66
|
+
readonly format: "metadata";
|
|
67
|
+
readonly additionalProperties: true;
|
|
68
|
+
};
|
|
69
|
+
};
|
|
70
|
+
readonly required: readonly ["chunk_id", "kb_id", "doc_id", "vector", "metadata"];
|
|
71
|
+
readonly additionalProperties: false;
|
|
72
|
+
};
|
|
73
|
+
/**
|
|
74
|
+
* Composite primary key for shared document table — includes `kb_id` to prevent
|
|
75
|
+
* cross-KB key collisions when multiple knowledge bases share the same table.
|
|
76
|
+
*/
|
|
77
|
+
export declare const SharedDocumentPrimaryKey: readonly ["kb_id", "doc_id"];
|
|
78
|
+
export type SharedDocumentPrimaryKey = typeof SharedDocumentPrimaryKey;
|
|
79
|
+
/**
|
|
80
|
+
* Composite primary key for shared chunk table — includes `kb_id` to prevent
|
|
81
|
+
* cross-KB key collisions when multiple knowledge bases share the same table.
|
|
82
|
+
*/
|
|
83
|
+
export declare const SharedChunkPrimaryKey: readonly ["kb_id", "chunk_id"];
|
|
84
|
+
export type SharedChunkPrimaryKey = typeof SharedChunkPrimaryKey;
|
|
85
|
+
/**
|
|
86
|
+
* Index definitions for efficient KB-scoped queries on shared document table.
|
|
87
|
+
*/
|
|
88
|
+
export declare const SharedDocumentIndexes: readonly [readonly ["kb_id"]];
|
|
89
|
+
/**
|
|
90
|
+
* Index definitions for efficient KB-scoped queries on shared chunk table.
|
|
91
|
+
*/
|
|
92
|
+
export declare const SharedChunkIndexes: readonly [readonly ["kb_id"], readonly ["kb_id", "doc_id"]];
|
|
93
|
+
//# sourceMappingURL=SharedTableSchemas.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SharedTableSchemas.d.ts","sourceRoot":"","sources":["../../src/knowledge-base/S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