@memrosetta/core 0.2.22 → 0.4.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/dist/index.d.ts CHANGED
@@ -2,6 +2,14 @@ import Database from 'better-sqlite3';
2
2
  import { Memory, MemoryState, MemoryInput, RelationType, MemoryRelation, SearchResult, SearchFilters, SearchQuery, SearchResponse, IMemoryEngine, CompressResult, MaintenanceResult, MemoryTier, MemoryQuality, TierConfig } from '@memrosetta/types';
3
3
  import { Embedder, ContradictionDetector } from '@memrosetta/embeddings';
4
4
 
5
+ /**
6
+ * Thrown when a memory ID referenced in an operation does not exist.
7
+ */
8
+ declare class MemoryNotFoundError extends Error {
9
+ readonly memoryId: string;
10
+ constructor(memoryId: string);
11
+ }
12
+
5
13
  interface SchemaOptions {
6
14
  readonly vectorEnabled?: boolean;
7
15
  readonly embeddingDimension?: number;
@@ -342,4 +350,4 @@ declare function determineTier(memory: {
342
350
  */
343
351
  declare function estimateTokens(content: string): number;
344
352
 
345
- export { DEFAULT_TIER_CONFIG, type MemoryRow, type PreparedStatements, type RelationStatements, type SchemaOptions, type SearchSqlResult, type SqliteEngineOptions, SqliteMemoryEngine, type VectorSearchResult, applyKeywordBoost, applyThreeFactorReranking, bruteForceVectorSearch, buildFtsQuery, buildSearchSql, computeActivation, computeEbbinghaus, convexCombinationMerge, createEngine, createPreparedStatements, createRelation, createRelationStatements, deduplicateResults, deriveMemoryState, determineTier, ensureSchema, estimateTokens, extractQueryTokens, ftsSearch, generateMemoryId, getRelationsByMemory, keywordsToString, normalizeScores, nowIso, rowToMemory, rrfMerge, rrfMergeWeighted, searchMemories, serializeEmbedding, storeBatchAsync, storeBatchInTransaction, storeMemory, storeMemoryAsync, stringToKeywords, updateAccessTracking, vectorSearch };
353
+ export { DEFAULT_TIER_CONFIG, MemoryNotFoundError, type MemoryRow, type PreparedStatements, type RelationStatements, type SchemaOptions, type SearchSqlResult, type SqliteEngineOptions, SqliteMemoryEngine, type VectorSearchResult, applyKeywordBoost, applyThreeFactorReranking, bruteForceVectorSearch, buildFtsQuery, buildSearchSql, computeActivation, computeEbbinghaus, convexCombinationMerge, createEngine, createPreparedStatements, createRelation, createRelationStatements, deduplicateResults, deriveMemoryState, determineTier, ensureSchema, estimateTokens, extractQueryTokens, ftsSearch, generateMemoryId, getRelationsByMemory, keywordsToString, normalizeScores, nowIso, rowToMemory, rrfMerge, rrfMergeWeighted, searchMemories, serializeEmbedding, storeBatchAsync, storeBatchInTransaction, storeMemory, storeMemoryAsync, stringToKeywords, updateAccessTracking, vectorSearch };
package/dist/index.js CHANGED
@@ -1,3 +1,13 @@
1
+ // src/errors.ts
2
+ var MemoryNotFoundError = class extends Error {
3
+ memoryId;
4
+ constructor(memoryId) {
5
+ super(`Memory not found: ${memoryId}`);
6
+ this.name = "MemoryNotFoundError";
7
+ this.memoryId = memoryId;
8
+ }
9
+ };
10
+
1
11
  // src/schema.ts
2
12
  var SCHEMA_V1 = `
3
13
  -- memories table
@@ -443,11 +453,11 @@ function createRelationStatements(db) {
443
453
  function createRelation(db, stmts, srcMemoryId, dstMemoryId, relationType, reason) {
444
454
  const srcExists = stmts.checkMemoryExists.get(srcMemoryId);
445
455
  if (!srcExists) {
446
- throw new Error(`Source memory not found: ${srcMemoryId}`);
456
+ throw new MemoryNotFoundError(srcMemoryId);
447
457
  }
448
458
  const dstExists = stmts.checkMemoryExists.get(dstMemoryId);
449
459
  if (!dstExists) {
450
- throw new Error(`Destination memory not found: ${dstMemoryId}`);
460
+ throw new MemoryNotFoundError(dstMemoryId);
451
461
  }
452
462
  const createdAt = nowIso();
453
463
  stmts.insertRelation.run(
@@ -792,7 +802,7 @@ function vectorSearch(db, queryVec, userId, limit, filters, useVecTable = true)
792
802
  if (!useVecTable) {
793
803
  return bruteForceVectorSearch(db, queryVec, userId, limit, filters);
794
804
  }
795
- const candidateLimit = Math.min(limit * 5, 200);
805
+ const candidateLimit = Math.min(limit * 10, 500);
796
806
  const vecBuf = Buffer.from(queryVec.buffer, queryVec.byteOffset, queryVec.byteLength);
797
807
  let candidates;
798
808
  try {
@@ -802,7 +812,10 @@ function vectorSearch(db, queryVec, userId, limit, filters, useVecTable = true)
802
812
  WHERE embedding MATCH ?
803
813
  AND k = ?
804
814
  `).all(vecBuf, candidateLimit);
805
- } catch {
815
+ } catch (err) {
816
+ const msg = err instanceof Error ? err.message : String(err);
817
+ process.stderr.write(`[memrosetta] vec_memories KNN unavailable, using brute-force fallback: ${msg}
818
+ `);
806
819
  return bruteForceVectorSearch(db, queryVec, userId, limit, filters);
807
820
  }
808
821
  if (candidates.length === 0) return [];
@@ -863,6 +876,9 @@ function vectorSearch(db, queryVec, userId, limit, filters, useVecTable = true)
863
876
  params.push(filters.eventDateRange.end);
864
877
  }
865
878
  const rows = db.prepare(sql).all(...params);
879
+ if (rows.length < limit) {
880
+ return bruteForceVectorSearch(db, queryVec, userId, limit, filters);
881
+ }
866
882
  return rows.map((row) => ({
867
883
  memory: rowToMemory(row),
868
884
  distance: distanceMap.get(row.id) ?? Infinity
@@ -1726,6 +1742,7 @@ function createEngine(options) {
1726
1742
  }
1727
1743
  export {
1728
1744
  DEFAULT_TIER_CONFIG,
1745
+ MemoryNotFoundError,
1729
1746
  SqliteMemoryEngine,
1730
1747
  applyKeywordBoost,
1731
1748
  applyThreeFactorReranking,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@memrosetta/core",
3
- "version": "0.2.22",
3
+ "version": "0.4.0",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -20,10 +20,10 @@
20
20
  "better-sqlite3": "^11.0.0",
21
21
  "nanoid": "^5.0.0",
22
22
  "sqlite-vec": "^0.1.7",
23
- "@memrosetta/types": "0.2.21"
23
+ "@memrosetta/types": "0.4.0"
24
24
  },
25
25
  "optionalDependencies": {
26
- "@memrosetta/embeddings": "0.2.21"
26
+ "@memrosetta/embeddings": "0.3.0"
27
27
  },
28
28
  "devDependencies": {
29
29
  "@types/better-sqlite3": "^7.6.0",