@signetai/core 0.203.8 → 0.203.10
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.js +59 -24
- package/dist/search.d.ts +1 -4
- package/dist/search.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -14960,42 +14960,77 @@ function cosineSimilarity(a, b) {
|
|
|
14960
14960
|
}
|
|
14961
14961
|
return tsCosineSimilarity(a, b);
|
|
14962
14962
|
}
|
|
14963
|
+
function withReadTransaction(db, read) {
|
|
14964
|
+
if (db.exec === undefined) {
|
|
14965
|
+
read();
|
|
14966
|
+
return;
|
|
14967
|
+
}
|
|
14968
|
+
db.exec("BEGIN");
|
|
14969
|
+
try {
|
|
14970
|
+
read();
|
|
14971
|
+
db.exec("COMMIT");
|
|
14972
|
+
} catch (error) {
|
|
14973
|
+
db.exec("ROLLBACK");
|
|
14974
|
+
throw error;
|
|
14975
|
+
}
|
|
14976
|
+
}
|
|
14977
|
+
function activeVectorSearchTables(db) {
|
|
14978
|
+
try {
|
|
14979
|
+
const row = db.prepare("SELECT active_profile_json, state, staging_profile_json FROM embedding_index_state WHERE id = 1").get();
|
|
14980
|
+
if (!row)
|
|
14981
|
+
return { projection: "vec_embeddings", embeddings: "embeddings" };
|
|
14982
|
+
const active = typeof row.active_profile_json === "string" ? JSON.parse(row.active_profile_json) : {};
|
|
14983
|
+
const activeProjection = active.projectionSlot === "staging" ? "vec_embeddings_staging" : "vec_embeddings";
|
|
14984
|
+
if (row.state !== "building" || typeof row.staging_profile_json !== "string") {
|
|
14985
|
+
return { projection: activeProjection, embeddings: "embeddings" };
|
|
14986
|
+
}
|
|
14987
|
+
const staging = JSON.parse(row.staging_profile_json);
|
|
14988
|
+
if (staging.projectionRebuild === true)
|
|
14989
|
+
return { projection: activeProjection, embeddings: "embeddings_staging" };
|
|
14990
|
+
return { projection: activeProjection, embeddings: "embeddings" };
|
|
14991
|
+
} catch {
|
|
14992
|
+
return { projection: "vec_embeddings", embeddings: "embeddings" };
|
|
14993
|
+
}
|
|
14994
|
+
}
|
|
14963
14995
|
function vectorSearch(db, queryVector, options) {
|
|
14964
14996
|
const limit = options?.limit ?? 20;
|
|
14965
14997
|
const results = [];
|
|
14966
14998
|
try {
|
|
14967
|
-
|
|
14968
|
-
|
|
14969
|
-
|
|
14970
|
-
|
|
14971
|
-
|
|
14972
|
-
|
|
14973
|
-
|
|
14974
|
-
typeFilter = "
|
|
14975
|
-
|
|
14976
|
-
|
|
14977
|
-
|
|
14978
|
-
|
|
14979
|
-
|
|
14980
|
-
|
|
14999
|
+
withReadTransaction(db, () => {
|
|
15000
|
+
const searchTables = activeVectorSearchTables(db);
|
|
15001
|
+
const queryBlob = new Float32Array(queryVector);
|
|
15002
|
+
const maxK = options?.excludeAggregateRecall ? Math.max(limit, Math.min(limit * 8, 1000)) : limit;
|
|
15003
|
+
let k = limit;
|
|
15004
|
+
while (true) {
|
|
15005
|
+
const params = [queryBlob, k];
|
|
15006
|
+
let typeFilter = "";
|
|
15007
|
+
if (options?.type) {
|
|
15008
|
+
typeFilter = " AND m.type = ?";
|
|
15009
|
+
params.push(options.type);
|
|
15010
|
+
}
|
|
15011
|
+
if (options?.excludeAggregateRecall) {
|
|
15012
|
+
typeFilter += " AND COALESCE(m.source_type, '') != 'aggregate-recall'";
|
|
15013
|
+
}
|
|
15014
|
+
const rows = db.prepare(`
|
|
14981
15015
|
SELECT
|
|
14982
15016
|
e.source_id,
|
|
14983
15017
|
v.distance
|
|
14984
|
-
FROM
|
|
14985
|
-
|
|
15018
|
+
FROM ${searchTables.projection} v
|
|
15019
|
+
JOIN ${searchTables.embeddings} e ON v.id = e.id
|
|
14986
15020
|
JOIN memories m ON e.source_id = m.id
|
|
14987
15021
|
WHERE v.embedding MATCH ? AND k = ?${typeFilter}
|
|
14988
15022
|
ORDER BY v.distance
|
|
14989
15023
|
`).all(...params);
|
|
14990
|
-
|
|
14991
|
-
|
|
14992
|
-
|
|
14993
|
-
|
|
15024
|
+
results.length = 0;
|
|
15025
|
+
for (const row of rows.slice(0, limit)) {
|
|
15026
|
+
const similarity = 1 - row.distance;
|
|
15027
|
+
results.push({ id: row.source_id, score: Math.max(0, similarity) });
|
|
15028
|
+
}
|
|
15029
|
+
if (results.length >= limit || k >= maxK || !options?.excludeAggregateRecall && rows.length < k)
|
|
15030
|
+
break;
|
|
15031
|
+
k = Math.min(k * 2, maxK);
|
|
14994
15032
|
}
|
|
14995
|
-
|
|
14996
|
-
break;
|
|
14997
|
-
k = Math.min(k * 2, maxK);
|
|
14998
|
-
}
|
|
15033
|
+
});
|
|
14999
15034
|
} catch (e) {
|
|
15000
15035
|
console.warn("Vector search failed:", e);
|
|
15001
15036
|
}
|
package/dist/search.d.ts
CHANGED
|
@@ -32,6 +32,7 @@ export interface SearchResult {
|
|
|
32
32
|
* SQLite database interface for raw queries
|
|
33
33
|
*/
|
|
34
34
|
interface SQLiteDatabase {
|
|
35
|
+
exec?(sql: string): void;
|
|
35
36
|
prepare(sql: string): {
|
|
36
37
|
run(...args: unknown[]): void;
|
|
37
38
|
get(...args: unknown[]): Record<string, unknown> | undefined;
|
|
@@ -47,10 +48,6 @@ interface DatabaseWrapper {
|
|
|
47
48
|
}
|
|
48
49
|
export declare function buildFtsMatchQuery(query: string): string | null;
|
|
49
50
|
export declare function cosineSimilarity(a: Float32Array, b: Float32Array): number;
|
|
50
|
-
/**
|
|
51
|
-
* Pure vector search using sqlite-vec
|
|
52
|
-
* Uses the vec_embeddings virtual table for efficient similarity search
|
|
53
|
-
*/
|
|
54
51
|
export declare function vectorSearch(db: SQLiteDatabase, queryVector: Float32Array, options?: VectorSearchOptions): Array<{
|
|
55
52
|
id: string;
|
|
56
53
|
score: number;
|
package/dist/search.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"search.d.ts","sourceRoot":"","sources":["../src/search.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,MAAM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