@kernl-sdk/pg 0.1.21 → 0.1.23

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.
@@ -1,5 +1,4 @@
1
-
2
- 
3
- > @kernl-sdk/pg@0.1.20 build /Users/andjones/Documents/projects/kernl/packages/storage/pg
4
- > tsc && tsc-alias --resolve-full-paths
5
-
1
+
2
+ > @kernl-sdk/pg@0.1.23 build /home/runner/work/kernl/kernl/packages/storage/pg
3
+ > tsc && tsc-alias --resolve-full-paths
4
+
package/CHANGELOG.md CHANGED
@@ -1,5 +1,21 @@
1
1
  # @kernl/pg
2
2
 
3
+ ## 0.1.23
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [e90b227]
8
+ - kernl@0.8.4
9
+ - @kernl-sdk/storage@0.1.23
10
+
11
+ ## 0.1.22
12
+
13
+ ### Patch Changes
14
+
15
+ - Updated dependencies [ae11e54]
16
+ - kernl@0.8.3
17
+ - @kernl-sdk/storage@0.1.22
18
+
3
19
  ## 0.1.21
4
20
 
5
21
  ### Patch Changes
@@ -1 +1 @@
1
- {"version":3,"file":"memory-integration.test.d.ts","sourceRoot":"","sources":["../../src/__tests__/memory-integration.test.ts"],"names":[],"mappings":"AAIA,OAAO,sBAAsB,CAAC"}
1
+ {"version":3,"file":"memory-integration.test.d.ts","sourceRoot":"","sources":["../../src/__tests__/memory-integration.test.ts"],"names":[],"mappings":"AAKA,OAAO,sBAAsB,CAAC"}
@@ -26,7 +26,7 @@ describe.sequential("Memory Integration with PGVector", { timeout: 30000 }, () =
26
26
  vector: pgvector({ pool }),
27
27
  },
28
28
  memory: {
29
- embeddingModel: "openai/text-embedding-3-small",
29
+ embedding: "openai/text-embedding-3-small",
30
30
  dimensions: 1536,
31
31
  },
32
32
  });
@@ -204,7 +204,7 @@ describe.sequential("Memory Integration with PGVector", { timeout: 30000 }, () =
204
204
  vector: pgvector({ pool }),
205
205
  },
206
206
  memory: {
207
- embeddingModel: "openai/text-embedding-3-small",
207
+ embedding: "openai/text-embedding-3-small",
208
208
  dimensions: 1536,
209
209
  },
210
210
  });
@@ -253,13 +253,62 @@ describe.sequential("Memory Integration with PGVector", { timeout: 30000 }, () =
253
253
  id: "m1",
254
254
  metadata: { version: 2, updated: true },
255
255
  });
256
- // Verify metadata updated in vector index
257
- const vectorResult = await pool.query('SELECT metadata FROM "kernl"."memories_sindex" WHERE id = $1', ["m1"]);
258
- expect(vectorResult.rows[0].metadata).toEqual({
256
+ // Verify metadata updated in primary DB (metadata is not indexed)
257
+ const dbResult = await pool.query('SELECT metadata FROM "kernl"."memories" WHERE id = $1', ["m1"]);
258
+ expect(dbResult.rows[0].metadata).toEqual({
259
259
  version: 2,
260
260
  updated: true,
261
261
  });
262
262
  });
263
+ it("isolates memories by agentId", async () => {
264
+ // Register two agents
265
+ const model = {
266
+ spec: "1.0",
267
+ provider: "test",
268
+ modelId: "test-model",
269
+ };
270
+ const agent1 = new Agent({
271
+ id: "test-agent-1",
272
+ name: "Test Agent 1",
273
+ instructions: () => "test instructions",
274
+ model,
275
+ });
276
+ const agent2 = new Agent({
277
+ id: "test-agent-2",
278
+ name: "Test Agent 2",
279
+ instructions: () => "test instructions",
280
+ model,
281
+ });
282
+ kernl.register(agent1);
283
+ kernl.register(agent2);
284
+ // Create memories for each agent in the same namespace
285
+ await agent1.memories.create({
286
+ namespace: "shared-ns",
287
+ collection: "facts",
288
+ content: { text: "Agent 1 knows about cats" },
289
+ });
290
+ await agent2.memories.create({
291
+ namespace: "shared-ns",
292
+ collection: "facts",
293
+ content: { text: "Agent 2 knows about cats" },
294
+ });
295
+ // Search from agent1 - should only see agent1's memory
296
+ const results1 = await agent1.memories.search({
297
+ query: "cats",
298
+ filter: { scope: { namespace: "shared-ns" } },
299
+ limit: 10,
300
+ });
301
+ // Search from agent2 - should only see agent2's memory
302
+ const results2 = await agent2.memories.search({
303
+ query: "cats",
304
+ filter: { scope: { namespace: "shared-ns" } },
305
+ limit: 10,
306
+ });
307
+ expect(results1).toHaveLength(1);
308
+ expect(results1[0].document?.agentId).toBe("test-agent-1");
309
+ expect(results2).toHaveLength(1);
310
+ expect(results2[0].document?.agentId).toBe("test-agent-2");
311
+ });
263
312
  it("creates memories with multimodal content", async () => {
264
313
  await kernl.memories.create({
265
314
  id: "m1",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kernl-sdk/pg",
3
- "version": "0.1.21",
3
+ "version": "0.1.23",
4
4
  "description": "PostgreSQL storage adapter for kernl",
5
5
  "keywords": [
6
6
  "kernl",
@@ -40,10 +40,10 @@
40
40
  },
41
41
  "dependencies": {
42
42
  "pg": "^8.16.3",
43
- "kernl": "^0.8.2",
43
+ "kernl": "^0.8.4",
44
44
  "@kernl-sdk/retrieval": "^0.1.3",
45
45
  "@kernl-sdk/shared": "^0.3.0",
46
- "@kernl-sdk/storage": "0.1.21"
46
+ "@kernl-sdk/storage": "0.1.23"
47
47
  },
48
48
  "scripts": {
49
49
  "clean": "rm -rf dist",
@@ -2,6 +2,7 @@ import { describe, it, expect, beforeAll, afterAll, beforeEach } from "vitest";
2
2
  import { Pool } from "pg";
3
3
  import { Kernl, Agent } from "kernl";
4
4
  import type { LanguageModel } from "@kernl-sdk/protocol";
5
+ import type { SearchHit } from "@kernl-sdk/retrieval";
5
6
  import "@kernl-sdk/ai/openai"; // Register OpenAI embedding provider
6
7
 
7
8
  import { postgres, pgvector } from "../index";
@@ -38,7 +39,7 @@ describe.sequential(
38
39
  vector: pgvector({ pool }),
39
40
  },
40
41
  memory: {
41
- embeddingModel: "openai/text-embedding-3-small",
42
+ embedding: "openai/text-embedding-3-small",
42
43
  dimensions: 1536,
43
44
  },
44
45
  });
@@ -149,7 +150,7 @@ describe.sequential(
149
150
  expect(results.length).toBeGreaterThan(0);
150
151
 
151
152
  // Should find TypeScript-related memories with higher scores
152
- const ids = results.map((r) => r.document?.id);
153
+ const ids = results.map((r: SearchHit) => r.document?.id);
153
154
  expect(ids).toContain("m1"); // Direct match
154
155
  expect(ids).toContain("m3"); // Related to TypeScript
155
156
  });
@@ -255,7 +256,7 @@ describe.sequential(
255
256
  vector: pgvector({ pool }),
256
257
  },
257
258
  memory: {
258
- embeddingModel: "openai/text-embedding-3-small",
259
+ embedding: "openai/text-embedding-3-small",
259
260
  dimensions: 1536,
260
261
  },
261
262
  });
@@ -292,7 +293,7 @@ describe.sequential(
292
293
  });
293
294
 
294
295
  expect(results.length).toBeGreaterThan(0);
295
- const match = results.find((r) => r.document?.id === "m1");
296
+ const match = results.find((r: SearchHit) => r.document?.id === "m1");
296
297
  expect(match).toBeDefined();
297
298
  expect(match?.document?.text).toBe("Updated content about cats");
298
299
  });
@@ -313,18 +314,75 @@ describe.sequential(
313
314
  metadata: { version: 2, updated: true },
314
315
  });
315
316
 
316
- // Verify metadata updated in vector index
317
- const vectorResult = await pool.query(
318
- 'SELECT metadata FROM "kernl"."memories_sindex" WHERE id = $1',
317
+ // Verify metadata updated in primary DB (metadata is not indexed)
318
+ const dbResult = await pool.query(
319
+ 'SELECT metadata FROM "kernl"."memories" WHERE id = $1',
319
320
  ["m1"],
320
321
  );
321
322
 
322
- expect(vectorResult.rows[0].metadata).toEqual({
323
+ expect(dbResult.rows[0].metadata).toEqual({
323
324
  version: 2,
324
325
  updated: true,
325
326
  });
326
327
  });
327
328
 
329
+ it("isolates memories by agentId", async () => {
330
+ // Register two agents
331
+ const model = {
332
+ spec: "1.0" as const,
333
+ provider: "test",
334
+ modelId: "test-model",
335
+ } as unknown as LanguageModel;
336
+
337
+ const agent1 = new Agent({
338
+ id: "test-agent-1",
339
+ name: "Test Agent 1",
340
+ instructions: () => "test instructions",
341
+ model,
342
+ });
343
+ const agent2 = new Agent({
344
+ id: "test-agent-2",
345
+ name: "Test Agent 2",
346
+ instructions: () => "test instructions",
347
+ model,
348
+ });
349
+ kernl.register(agent1);
350
+ kernl.register(agent2);
351
+
352
+ // Create memories for each agent in the same namespace
353
+ await agent1.memories.create({
354
+ namespace: "shared-ns",
355
+ collection: "facts",
356
+ content: { text: "Agent 1 knows about cats" },
357
+ });
358
+
359
+ await agent2.memories.create({
360
+ namespace: "shared-ns",
361
+ collection: "facts",
362
+ content: { text: "Agent 2 knows about cats" },
363
+ });
364
+
365
+ // Search from agent1 - should only see agent1's memory
366
+ const results1 = await agent1.memories.search({
367
+ query: "cats",
368
+ filter: { scope: { namespace: "shared-ns" } },
369
+ limit: 10,
370
+ });
371
+
372
+ // Search from agent2 - should only see agent2's memory
373
+ const results2 = await agent2.memories.search({
374
+ query: "cats",
375
+ filter: { scope: { namespace: "shared-ns" } },
376
+ limit: 10,
377
+ });
378
+
379
+ expect(results1).toHaveLength(1);
380
+ expect(results1[0].document?.agentId).toBe("test-agent-1");
381
+
382
+ expect(results2).toHaveLength(1);
383
+ expect(results2[0].document?.agentId).toBe("test-agent-2");
384
+ });
385
+
328
386
  it("creates memories with multimodal content", async () => {
329
387
  await kernl.memories.create({
330
388
  id: "m1",
@@ -348,7 +406,7 @@ describe.sequential(
348
406
  });
349
407
 
350
408
  expect(results.length).toBeGreaterThan(0);
351
- const match = results.find((r) => r.document?.id === "m1");
409
+ const match = results.find((r: SearchHit) => r.document?.id === "m1");
352
410
  expect(match).toBeDefined();
353
411
  });
354
412
  },
@@ -1,36 +0,0 @@
1
-
2
- > @kernl-sdk/pg@0.1.11 check-types /Users/andjones/Documents/projects/kernl/packages/storage/pg
3
- > tsc --noEmit
4
-
5
- src/search/__tests__/hit.test.ts(75,55): error TS2345: Argument of type '{ schema: string; table: string; fields: { title: { column: string; type: "string"; }; content: { column: string; type: "string"; }; embedding: { column: string; type: "vector"; dimensions: number; }; }; }' is not assignable to parameter of type 'PGIndexConfig'.
6
- Property 'pkey' is missing in type '{ schema: string; table: string; fields: { title: { column: string; type: "string"; }; content: { column: string; type: "string"; }; embedding: { column: string; type: "vector"; dimensions: number; }; }; }' but required in type 'PGIndexConfig'.
7
- src/search/__tests__/hit.test.ts(93,55): error TS2345: Argument of type '{ schema: string; table: string; fields: { title: { column: string; type: "string"; }; content: { column: string; type: "string"; }; embedding: { column: string; type: "vector"; dimensions: number; }; }; }' is not assignable to parameter of type 'PGIndexConfig'.
8
- Property 'pkey' is missing in type '{ schema: string; table: string; fields: { title: { column: string; type: "string"; }; content: { column: string; type: "string"; }; embedding: { column: string; type: "vector"; dimensions: number; }; }; }' but required in type 'PGIndexConfig'.
9
- src/search/__tests__/hit.test.ts(110,55): error TS2345: Argument of type '{ schema: string; table: string; fields: { title: { column: string; type: "string"; }; content: { column: string; type: "string"; }; embedding: { column: string; type: "vector"; dimensions: number; }; }; }' is not assignable to parameter of type 'PGIndexConfig'.
10
- Property 'pkey' is missing in type '{ schema: string; table: string; fields: { title: { column: string; type: "string"; }; content: { column: string; type: "string"; }; embedding: { column: string; type: "vector"; dimensions: number; }; }; }' but required in type 'PGIndexConfig'.
11
- src/search/__tests__/hit.test.ts(124,55): error TS2345: Argument of type '{ schema: string; table: string; fields: { title: { column: string; type: "string"; }; content: { column: string; type: "string"; }; embedding: { column: string; type: "vector"; dimensions: number; }; }; }' is not assignable to parameter of type 'PGIndexConfig'.
12
- Property 'pkey' is missing in type '{ schema: string; table: string; fields: { title: { column: string; type: "string"; }; content: { column: string; type: "string"; }; embedding: { column: string; type: "vector"; dimensions: number; }; }; }' but required in type 'PGIndexConfig'.
13
- src/search/sql/__tests__/order.test.ts(58,11): error TS2741: Property 'pkey' is missing in type '{ schema: string; table: string; fields: { embedding: { column: string; type: "vector"; dimensions: number; similarity: "cosine"; }; }; }' but required in type 'PGIndexConfig'.
14
- src/search/sql/__tests__/order.test.ts(77,11): error TS2741: Property 'pkey' is missing in type '{ schema: string; table: string; fields: { embedding: { column: string; type: "vector"; dimensions: number; similarity: "euclidean"; }; }; }' but required in type 'PGIndexConfig'.
15
- src/search/sql/__tests__/order.test.ts(96,11): error TS2741: Property 'pkey' is missing in type '{ schema: string; table: string; fields: { embedding: { column: string; type: "vector"; dimensions: number; similarity: "dot_product"; }; }; }' but required in type 'PGIndexConfig'.
16
- src/search/sql/__tests__/order.test.ts(134,11): error TS2741: Property 'pkey' is missing in type '{ schema: string; table: string; fields: { other_field: { column: string; type: "vector"; dimensions: number; similarity: "euclidean"; }; }; }' but required in type 'PGIndexConfig'.
17
- src/search/sql/__tests__/query.test.ts(110,21): error TS2741: Property 'pkey' is missing in type '{ schema: string; table: string; fields: { embedding: { column: string; type: "vector"; dimensions: number; similarity: "cosine"; }; }; }' but required in type 'PGIndexConfig'.
18
- src/search/sql/__tests__/query.test.ts(196,23): error TS2741: Property 'pkey' is missing in type '{ schema: string; table: string; fields: { embedding: { column: string; type: "vector"; dimensions: number; similarity: "cosine"; }; }; }' but required in type 'PGIndexConfig'.
19
- src/search/sql/__tests__/query.test.ts(258,27): error TS2741: Property 'pkey' is missing in type '{ schema: string; table: string; fields: { embedding: { column: string; type: "vector"; dimensions: number; similarity: "euclidean"; }; }; }' but required in type 'PGIndexConfig'.
20
- src/search/sql/__tests__/query.test.ts(324,25): error TS2741: Property 'pkey' is missing in type '{ schema: string; table: string; fields: { embedding: { column: string; type: "vector"; dimensions: number; similarity: "cosine"; }; }; }' but required in type 'PGIndexConfig'.
21
- src/search/sql/__tests__/query.test.ts(462,21): error TS2741: Property 'pkey' is missing in type '{ schema: string; table: string; fields: { embedding: { column: string; type: "vector"; dimensions: number; similarity: "euclidean"; }; }; }' but required in type 'PGIndexConfig'.
22
- src/search/sql/__tests__/query.test.ts(492,21): error TS2741: Property 'pkey' is missing in type '{ schema: string; table: string; fields: { embedding: { column: string; type: "vector"; dimensions: number; similarity: "dot_product"; }; }; }' but required in type 'PGIndexConfig'.
23
- src/search/sql/__tests__/select.test.ts(43,9): error TS2741: Property 'pkey' is missing in type '{ schema: string; table: string; fields: { embedding: { column: string; type: "vector"; dimensions: number; similarity: "cosine"; }; }; }' but required in type 'PGIndexConfig'.
24
- src/search/sql/__tests__/select.test.ts(67,9): error TS2741: Property 'pkey' is missing in type '{ schema: string; table: string; fields: { embedding: { column: string; type: "vector"; dimensions: number; similarity: "euclidean"; }; }; }' but required in type 'PGIndexConfig'.
25
- src/search/sql/__tests__/select.test.ts(91,9): error TS2741: Property 'pkey' is missing in type '{ schema: string; table: string; fields: { embedding: { column: string; type: "vector"; dimensions: number; similarity: "dot_product"; }; }; }' but required in type 'PGIndexConfig'.
26
- src/search/sql/__tests__/select.test.ts(155,11): error TS2741: Property 'pkey' is missing in type '{ schema: string; table: string; fields: { other_field: { column: string; type: "vector"; dimensions: number; similarity: "cosine"; }; }; }' but required in type 'PGIndexConfig'.
27
- src/search/sql/__tests__/select.test.ts(300,9): error TS2741: Property 'pkey' is missing in type '{ schema: string; table: string; fields: { title: { column: string; type: "string"; }; content: { column: string; type: "string"; }; embedding: { column: string; type: "vector"; dimensions: number; similarity: "cosine"; }; }; }' but required in type 'PGIndexConfig'.
28
- src/search/sql/__tests__/select.test.ts(312,9): error TS2741: Property 'pkey' is missing in type '{ schema: string; table: string; fields: { title: { column: string; type: "string"; }; content: { column: string; type: "string"; }; embedding: { column: string; type: "vector"; dimensions: number; similarity: "cosine"; }; }; }' but required in type 'PGIndexConfig'.
29
- src/search/sql/__tests__/select.test.ts(325,9): error TS2741: Property 'pkey' is missing in type '{ schema: string; table: string; fields: { title: { column: string; type: "string"; }; content: { column: string; type: "string"; }; embedding: { column: string; type: "vector"; dimensions: number; similarity: "cosine"; }; }; }' but required in type 'PGIndexConfig'.
30
- src/search/sql/__tests__/select.test.ts(336,9): error TS2741: Property 'pkey' is missing in type '{ schema: string; table: string; fields: { title: { column: string; type: "string"; }; content: { column: string; type: "string"; }; embedding: { column: string; type: "vector"; dimensions: number; similarity: "cosine"; }; }; }' but required in type 'PGIndexConfig'.
31
- src/search/sql/__tests__/select.test.ts(347,9): error TS2741: Property 'pkey' is missing in type '{ schema: string; table: string; fields: { title: { column: string; type: "string"; }; content: { column: string; type: "string"; }; embedding: { column: string; type: "vector"; dimensions: number; similarity: "cosine"; }; }; }' but required in type 'PGIndexConfig'.
32
- src/search/sql/__tests__/where.test.ts(357,28): error TS2322: Type 'string' is not assignable to type 'Filter'.
33
- Type 'string' is not assignable to type '{ [field: string]: Filter | ScalarValue | FieldOps | Filter[] | undefined; }'.
34
- src/search/sql/__tests__/where.test.ts(357,33): error TS2322: Type 'string' is not assignable to type 'Filter'.
35
- Type 'string' is not assignable to type '{ [field: string]: Filter | ScalarValue | FieldOps | Filter[] | undefined; }'.
36
-  ELIFECYCLE  Command failed with exit code 2.
@@ -1 +0,0 @@
1
- {"root":["./src/index.ts","./src/migrations.ts","./src/postgres.ts","./src/sql.ts","./src/storage.ts","./src/__tests__/integration.test.ts","./src/__tests__/memory.test.ts","./src/__tests__/thread.test.ts","./src/memory/sql.ts","./src/memory/store.ts","./src/thread/sql.ts","./src/thread/store.ts"],"version":"5.9.2"}