@godspeedai/cognate-cognitive-memory 0.1.0 → 0.1.2
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 +97 -12
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1,14 +1,99 @@
|
|
|
1
1
|
# @godspeedai/cognate-cognitive-memory
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
plus a deterministic hashing embedder
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
3
|
+
The dependency-free fallback for Cognate semantic recall: an in-process `CognitiveIndex` with
|
|
4
|
+
exact cosine similarity, plus a deterministic hashing embedder. Nothing to install, no
|
|
5
|
+
network, no native code.
|
|
6
|
+
|
|
7
|
+
**When to use this package:** tests, small datasets, and offline development — or as the
|
|
8
|
+
correctness baseline other index implementations are compared against. For large corpora or
|
|
9
|
+
durable vector files, use
|
|
10
|
+
[`@godspeedai/cognate-cognitive-ruvector`](https://www.npmjs.com/package/@godspeedai/cognate-cognitive-ruvector)
|
|
11
|
+
or
|
|
12
|
+
[`@godspeedai/cognate-cognitive-rvf`](https://www.npmjs.com/package/@godspeedai/cognate-cognitive-rvf)
|
|
13
|
+
instead.
|
|
14
|
+
|
|
15
|
+
## Installation
|
|
16
|
+
|
|
17
|
+
```sh
|
|
18
|
+
bun add @godspeedai/cognate-cognitive-memory
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
Requires [Bun](https://bun.sh) >= 1.4.0. The SDK ships Bun-native TypeScript source, so add
|
|
22
|
+
`@types/bun` and `@types/node` as dev dependencies when typechecking your project.
|
|
23
|
+
|
|
24
|
+
## Quick start
|
|
25
|
+
|
|
26
|
+
```ts
|
|
27
|
+
import { createMemoryIndex, hashingEmbedder } from "@godspeedai/cognate-cognitive-memory";
|
|
28
|
+
|
|
29
|
+
const dimension = 8;
|
|
30
|
+
const index = createMemoryIndex({ dimension }); // id defaults to "memory"
|
|
31
|
+
const embedder = hashingEmbedder(dimension);
|
|
32
|
+
|
|
33
|
+
const [vector] = await embedder.embed(["Refunds are approved by a manager."]);
|
|
34
|
+
await index.upsert([{
|
|
35
|
+
id: "doc-1",
|
|
36
|
+
sourceType: "knowledge",
|
|
37
|
+
sourceRef: "knowledge:refund-policy", // the route back to authoritative content
|
|
38
|
+
tenant: "tenant-a",
|
|
39
|
+
scopeId: "root",
|
|
40
|
+
semanticRef: null,
|
|
41
|
+
eventRef: null,
|
|
42
|
+
traceRef: null,
|
|
43
|
+
embedding: vector!,
|
|
44
|
+
metadata: { title: "Refund policy" }, // non-sensitive metadata only
|
|
45
|
+
relationships: [], // e.g. [{ type: "about", target: "doc-2" }]
|
|
46
|
+
validFrom: new Date().toISOString(),
|
|
47
|
+
validTo: null,
|
|
48
|
+
indexerVersion: "1",
|
|
49
|
+
durable: true,
|
|
50
|
+
}]);
|
|
51
|
+
|
|
52
|
+
const [query] = await embedder.embed(["who approves refunds?"]);
|
|
53
|
+
const hits = await index.similar({ vector: query!, k: 3, tenant: "tenant-a" });
|
|
54
|
+
// [{ id: "doc-1", score: ... }] — highest similarity first
|
|
55
|
+
|
|
56
|
+
console.log(await index.count()); // 1
|
|
57
|
+
await index.close();
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
## Behavior
|
|
61
|
+
|
|
62
|
+
- **Filtering.** `similar` always filters by tenant, and by `scopeIds` when the query provides
|
|
63
|
+
them — another tenant's entries are never returned.
|
|
64
|
+
- **Graph traversal.** The index declares `graph_traversal`: `related(id, { types?, depth })`
|
|
65
|
+
walks `relationships` breadth-first, in discovery order, without duplicates, excluding the
|
|
66
|
+
start id. It also declares `temporal_search` (validity windows are carried on entries).
|
|
67
|
+
- **Safety.** Upserting an entry whose embedding has the wrong dimension throws before
|
|
68
|
+
anything is stored. Entries and embeddings are copied on the way in and out, so mutating a
|
|
69
|
+
result never corrupts the index.
|
|
70
|
+
- **The embedder.** `hashingEmbedder(dimension)` lowercases, tokenizes on non-alphanumerics,
|
|
71
|
+
feature-hashes tokens into `dimension` signed buckets, and L2-normalizes. It is
|
|
72
|
+
deterministic and instant, but *not semantic*: it captures token overlap, not meaning.
|
|
73
|
+
Empty text embeds to the zero vector. Swap in a real embedder (same `Embedder` interface)
|
|
74
|
+
for quality.
|
|
75
|
+
|
|
76
|
+
## Limitations
|
|
77
|
+
|
|
78
|
+
- **In-process only.** State lives in a `Map`; everything is gone when the process exits.
|
|
79
|
+
Rebuild from your event store via the indexer projection of
|
|
80
|
+
[`@godspeedai/cognate-cognitive-api`](https://www.npmjs.com/package/@godspeedai/cognate-cognitive-api).
|
|
81
|
+
- **Exact search.** Similarity scans every entry — O(n) per query. Fine for thousands of
|
|
82
|
+
entries, not for millions.
|
|
83
|
+
- Use a real embedding model for production recall; the hashing embedder is for tests and
|
|
84
|
+
bootstrapping.
|
|
85
|
+
|
|
86
|
+
## Related packages
|
|
87
|
+
|
|
88
|
+
- [`@godspeedai/cognate-cognitive-api`](https://www.npmjs.com/package/@godspeedai/cognate-cognitive-api) —
|
|
89
|
+
the `CognitiveIndex`/`Embedder` contract, recall pipeline, and conformance kit this
|
|
90
|
+
package satisfies.
|
|
91
|
+
- [`@godspeedai/cognate-cognitive-ruvector`](https://www.npmjs.com/package/@godspeedai/cognate-cognitive-ruvector) —
|
|
92
|
+
the same contract over the external RuVector library.
|
|
93
|
+
- [`@godspeedai/cognate-cognitive-rvf`](https://www.npmjs.com/package/@godspeedai/cognate-cognitive-rvf) —
|
|
94
|
+
the same contract over RVF files with snapshot/branch support.
|
|
95
|
+
- [`@godspeedai/cognate`](https://www.npmjs.com/package/@godspeedai/cognate) — the SDK umbrella.
|
|
96
|
+
|
|
97
|
+
## License
|
|
98
|
+
|
|
99
|
+
Apache-2.0
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@godspeedai/cognate-cognitive-memory",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"description": "In-process exact-cosine CognitiveIndex and a deterministic hashing embedder; the fallback implementation for core cognition.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -22,6 +22,6 @@
|
|
|
22
22
|
".": "./src/index.ts"
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@godspeedai/cognate-cognitive-api": "^0.1.
|
|
25
|
+
"@godspeedai/cognate-cognitive-api": "^0.1.2"
|
|
26
26
|
}
|
|
27
27
|
}
|