audrey 0.14.0 → 0.16.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.
@@ -1,51 +1,51 @@
1
- export function interferenceModifier(interferenceCount, weight = 0.1) {
2
- return 1 / (1 + weight * interferenceCount);
3
- }
4
-
5
- export async function applyInterference(db, embeddingProvider, episodeId, { content }, config = {}) {
6
- const { enabled = true, k = 5, threshold = 0.6, weight = 0.1 } = config;
7
-
8
- if (!enabled) return [];
9
-
10
- const vector = await embeddingProvider.embed(content);
11
- const buffer = embeddingProvider.vectorToBuffer(vector);
12
-
13
- const semanticHits = db.prepare(`
14
- SELECT s.id, s.interference_count, (1.0 - v.distance) AS similarity
15
- FROM vec_semantics v
16
- JOIN semantics s ON s.id = v.id
17
- WHERE v.embedding MATCH ?
18
- AND k = ?
19
- AND (v.state = 'active' OR v.state = 'context_dependent')
20
- `).all(buffer, k);
21
-
22
- const proceduralHits = db.prepare(`
23
- SELECT p.id, p.interference_count, (1.0 - v.distance) AS similarity
24
- FROM vec_procedures v
25
- JOIN procedures p ON p.id = v.id
26
- WHERE v.embedding MATCH ?
27
- AND k = ?
28
- AND (v.state = 'active' OR v.state = 'context_dependent')
29
- `).all(buffer, k);
30
-
31
- const affected = [];
32
-
33
- const updateSemantic = db.prepare('UPDATE semantics SET interference_count = ? WHERE id = ?');
34
- const updateProcedural = db.prepare('UPDATE procedures SET interference_count = ? WHERE id = ?');
35
-
36
- for (const hit of semanticHits) {
37
- if (hit.similarity < threshold) continue;
38
- const newCount = hit.interference_count + 1;
39
- updateSemantic.run(newCount, hit.id);
40
- affected.push({ id: hit.id, type: 'semantic', newCount, similarity: hit.similarity });
41
- }
42
-
43
- for (const hit of proceduralHits) {
44
- if (hit.similarity < threshold) continue;
45
- const newCount = hit.interference_count + 1;
46
- updateProcedural.run(newCount, hit.id);
47
- affected.push({ id: hit.id, type: 'procedural', newCount, similarity: hit.similarity });
48
- }
49
-
50
- return affected;
51
- }
1
+ export function interferenceModifier(interferenceCount, weight = 0.1) {
2
+ return 1 / (1 + weight * interferenceCount);
3
+ }
4
+
5
+ export async function applyInterference(db, embeddingProvider, episodeId, { content }, config = {}) {
6
+ const { enabled = true, k = 5, threshold = 0.6, weight = 0.1 } = config;
7
+
8
+ if (!enabled) return [];
9
+
10
+ const vector = await embeddingProvider.embed(content);
11
+ const buffer = embeddingProvider.vectorToBuffer(vector);
12
+
13
+ const semanticHits = db.prepare(`
14
+ SELECT s.id, s.interference_count, (1.0 - v.distance) AS similarity
15
+ FROM vec_semantics v
16
+ JOIN semantics s ON s.id = v.id
17
+ WHERE v.embedding MATCH ?
18
+ AND k = ?
19
+ AND (v.state = 'active' OR v.state = 'context_dependent')
20
+ `).all(buffer, k);
21
+
22
+ const proceduralHits = db.prepare(`
23
+ SELECT p.id, p.interference_count, (1.0 - v.distance) AS similarity
24
+ FROM vec_procedures v
25
+ JOIN procedures p ON p.id = v.id
26
+ WHERE v.embedding MATCH ?
27
+ AND k = ?
28
+ AND (v.state = 'active' OR v.state = 'context_dependent')
29
+ `).all(buffer, k);
30
+
31
+ const affected = [];
32
+
33
+ const updateSemantic = db.prepare('UPDATE semantics SET interference_count = ? WHERE id = ?');
34
+ const updateProcedural = db.prepare('UPDATE procedures SET interference_count = ? WHERE id = ?');
35
+
36
+ for (const hit of semanticHits) {
37
+ if (hit.similarity < threshold) continue;
38
+ const newCount = hit.interference_count + 1;
39
+ updateSemantic.run(newCount, hit.id);
40
+ affected.push({ id: hit.id, type: 'semantic', newCount, similarity: hit.similarity });
41
+ }
42
+
43
+ for (const hit of proceduralHits) {
44
+ if (hit.similarity < threshold) continue;
45
+ const newCount = hit.interference_count + 1;
46
+ updateProcedural.run(newCount, hit.id);
47
+ affected.push({ id: hit.id, type: 'procedural', newCount, similarity: hit.similarity });
48
+ }
49
+
50
+ return affected;
51
+ }
package/src/introspect.js CHANGED
@@ -1,48 +1,48 @@
1
- import { safeJsonParse } from './utils.js';
2
-
3
- /**
4
- * @param {import('better-sqlite3').Database} db
5
- * @returns {{ episodic: number, semantic: number, procedural: number, causalLinks: number, dormant: number, contradictions: { open: number, resolved: number, context_dependent: number, reopened: number }, lastConsolidation: string|null, totalConsolidationRuns: number }}
6
- */
7
- export function introspect(db) {
8
- const counts = db.prepare(`
9
- SELECT
10
- (SELECT COUNT(*) FROM episodes) as episodic,
11
- (SELECT COUNT(*) FROM semantics WHERE state != 'rolled_back') as semantic,
12
- (SELECT COUNT(*) FROM procedures WHERE state != 'rolled_back') as procedural,
13
- (SELECT COUNT(*) FROM causal_links) as causal_links,
14
- (SELECT COUNT(*) FROM semantics WHERE state = 'dormant')
15
- + (SELECT COUNT(*) FROM procedures WHERE state = 'dormant') as dormant
16
- `).get();
17
-
18
- const contradictions = db.prepare(`
19
- SELECT
20
- SUM(CASE WHEN state = 'open' THEN 1 ELSE 0 END) as open,
21
- SUM(CASE WHEN state = 'resolved' THEN 1 ELSE 0 END) as resolved,
22
- SUM(CASE WHEN state = 'context_dependent' THEN 1 ELSE 0 END) as context_dependent,
23
- SUM(CASE WHEN state = 'reopened' THEN 1 ELSE 0 END) as reopened
24
- FROM contradictions
25
- `).get();
26
-
27
- const lastRun = db.prepare(`
28
- SELECT completed_at FROM consolidation_runs
29
- WHERE status = 'completed' ORDER BY completed_at DESC LIMIT 1
30
- `).get();
31
- const totalRuns = db.prepare('SELECT COUNT(*) as count FROM consolidation_runs').get().count;
32
-
33
- return {
34
- episodic: counts.episodic,
35
- semantic: counts.semantic,
36
- procedural: counts.procedural,
37
- causalLinks: counts.causal_links,
38
- dormant: counts.dormant,
39
- contradictions: {
40
- open: contradictions?.open || 0,
41
- resolved: contradictions?.resolved || 0,
42
- context_dependent: contradictions?.context_dependent || 0,
43
- reopened: contradictions?.reopened || 0,
44
- },
45
- lastConsolidation: lastRun?.completed_at || null,
46
- totalConsolidationRuns: totalRuns,
47
- };
48
- }
1
+ import { safeJsonParse } from './utils.js';
2
+
3
+ /**
4
+ * @param {import('better-sqlite3').Database} db
5
+ * @returns {{ episodic: number, semantic: number, procedural: number, causalLinks: number, dormant: number, contradictions: { open: number, resolved: number, context_dependent: number, reopened: number }, lastConsolidation: string|null, totalConsolidationRuns: number }}
6
+ */
7
+ export function introspect(db) {
8
+ const counts = db.prepare(`
9
+ SELECT
10
+ (SELECT COUNT(*) FROM episodes) as episodic,
11
+ (SELECT COUNT(*) FROM semantics WHERE state != 'rolled_back') as semantic,
12
+ (SELECT COUNT(*) FROM procedures WHERE state != 'rolled_back') as procedural,
13
+ (SELECT COUNT(*) FROM causal_links) as causal_links,
14
+ (SELECT COUNT(*) FROM semantics WHERE state = 'dormant')
15
+ + (SELECT COUNT(*) FROM procedures WHERE state = 'dormant') as dormant
16
+ `).get();
17
+
18
+ const contradictions = db.prepare(`
19
+ SELECT
20
+ SUM(CASE WHEN state = 'open' THEN 1 ELSE 0 END) as open,
21
+ SUM(CASE WHEN state = 'resolved' THEN 1 ELSE 0 END) as resolved,
22
+ SUM(CASE WHEN state = 'context_dependent' THEN 1 ELSE 0 END) as context_dependent,
23
+ SUM(CASE WHEN state = 'reopened' THEN 1 ELSE 0 END) as reopened
24
+ FROM contradictions
25
+ `).get();
26
+
27
+ const lastRun = db.prepare(`
28
+ SELECT completed_at FROM consolidation_runs
29
+ WHERE status = 'completed' ORDER BY completed_at DESC LIMIT 1
30
+ `).get();
31
+ const totalRuns = db.prepare('SELECT COUNT(*) as count FROM consolidation_runs').get().count;
32
+
33
+ return {
34
+ episodic: counts.episodic,
35
+ semantic: counts.semantic,
36
+ procedural: counts.procedural,
37
+ causalLinks: counts.causal_links,
38
+ dormant: counts.dormant,
39
+ contradictions: {
40
+ open: contradictions?.open || 0,
41
+ resolved: contradictions?.resolved || 0,
42
+ context_dependent: contradictions?.context_dependent || 0,
43
+ reopened: contradictions?.reopened || 0,
44
+ },
45
+ lastConsolidation: lastRun?.completed_at || null,
46
+ totalConsolidationRuns: totalRuns,
47
+ };
48
+ }