audrey 0.9.0 → 0.14.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/src/recall.js CHANGED
@@ -150,7 +150,8 @@ function matchesDateFilters(createdAt, filters) {
150
150
  return true;
151
151
  }
152
152
 
153
- function knnEpisodic(db, queryBuffer, candidateK, now, minConfidence, includeProvenance, confidenceConfig, filters = {}) {
153
+ function knnEpisodic(db, queryBuffer, candidateK, now, minConfidence, includeProvenance, confidenceConfig, filters = {}, includePrivate = false) {
154
+ const privateClause = includePrivate ? '' : 'AND e."private" = 0';
154
155
  const rows = db.prepare(`
155
156
  SELECT e.*, (1.0 - v.distance) AS similarity
156
157
  FROM vec_episodes v
@@ -158,6 +159,7 @@ function knnEpisodic(db, queryBuffer, candidateK, now, minConfidence, includePro
158
159
  WHERE v.embedding MATCH ?
159
160
  AND k = ?
160
161
  AND e.superseded_by IS NULL
162
+ ${privateClause}
161
163
  `).all(queryBuffer, candidateK);
162
164
 
163
165
  const results = [];
@@ -258,6 +260,7 @@ export async function* recallStream(db, embeddingProvider, query, options = {})
258
260
  sources,
259
261
  after,
260
262
  before,
263
+ includePrivate = false,
261
264
  } = options;
262
265
 
263
266
  const queryVector = await embeddingProvider.embed(query);
@@ -271,7 +274,7 @@ export async function* recallStream(db, embeddingProvider, query, options = {})
271
274
  const allResults = [];
272
275
 
273
276
  if (searchTypes.includes('episodic')) {
274
- const episodic = knnEpisodic(db, queryBuffer, candidateK, now, minConfidence, includeProvenance, confidenceConfig, filters);
277
+ const episodic = knnEpisodic(db, queryBuffer, candidateK, now, minConfidence, includeProvenance, confidenceConfig, filters, includePrivate);
275
278
  allResults.push(...episodic);
276
279
  }
277
280
 
@@ -281,13 +284,11 @@ export async function* recallStream(db, embeddingProvider, query, options = {})
281
284
  allResults.push(...semResults);
282
285
 
283
286
  if (semIds.length > 0) {
284
- const updateStmt = db.prepare(
285
- 'UPDATE semantics SET retrieval_count = retrieval_count + 1, last_reinforced_at = ? WHERE id = ?'
286
- );
287
287
  const nowISO = now.toISOString();
288
- for (const id of semIds) {
289
- updateStmt.run(nowISO, id);
290
- }
288
+ const placeholders = semIds.map(() => '?').join(',');
289
+ db.prepare(
290
+ `UPDATE semantics SET retrieval_count = retrieval_count + 1, last_reinforced_at = ? WHERE id IN (${placeholders})`
291
+ ).run(nowISO, ...semIds);
291
292
  }
292
293
  }
293
294
 
@@ -297,13 +298,11 @@ export async function* recallStream(db, embeddingProvider, query, options = {})
297
298
  allResults.push(...procResults);
298
299
 
299
300
  if (procIds.length > 0) {
300
- const updateStmt = db.prepare(
301
- 'UPDATE procedures SET retrieval_count = retrieval_count + 1, last_reinforced_at = ? WHERE id = ?'
302
- );
303
301
  const nowISO = now.toISOString();
304
- for (const id of procIds) {
305
- updateStmt.run(nowISO, id);
306
- }
302
+ const placeholders = procIds.map(() => '?').join(',');
303
+ db.prepare(
304
+ `UPDATE procedures SET retrieval_count = retrieval_count + 1, last_reinforced_at = ? WHERE id IN (${placeholders})`
305
+ ).run(nowISO, ...procIds);
307
306
  }
308
307
  }
309
308