@nicia-ai/typegraph 0.23.0 → 0.24.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/backend/postgres/index.cjs +29 -29
- package/dist/backend/postgres/index.js +2 -2
- package/dist/backend/sqlite/index.cjs +12 -12
- package/dist/backend/sqlite/index.js +2 -2
- package/dist/backend/sqlite/libsql.cjs +5 -5
- package/dist/backend/sqlite/libsql.js +2 -2
- package/dist/backend/sqlite/local.cjs +5 -5
- package/dist/backend/sqlite/local.js +2 -2
- package/dist/{chunk-O5BRZEIZ.cjs → chunk-3MDBMCFF.cjs} +53 -25
- package/dist/chunk-3MDBMCFF.cjs.map +1 -0
- package/dist/{chunk-7OD2EPN4.cjs → chunk-5HVDOPZU.cjs} +70 -5
- package/dist/chunk-5HVDOPZU.cjs.map +1 -0
- package/dist/{chunk-H2CAJ4ZV.js → chunk-EY4LBX3F.js} +70 -5
- package/dist/chunk-EY4LBX3F.js.map +1 -0
- package/dist/{chunk-EP2KSSD5.js → chunk-GTG5J4UP.js} +38 -10
- package/dist/chunk-GTG5J4UP.js.map +1 -0
- package/package.json +1 -1
- package/dist/chunk-7OD2EPN4.cjs.map +0 -1
- package/dist/chunk-EP2KSSD5.js.map +0 -1
- package/dist/chunk-H2CAJ4ZV.js.map +0 -1
- package/dist/chunk-O5BRZEIZ.cjs.map +0 -1
|
@@ -1903,9 +1903,7 @@ function buildVectorSearchMinScoreCondition(distanceExpression, metric, minScore
|
|
|
1903
1903
|
}
|
|
1904
1904
|
}
|
|
1905
1905
|
}
|
|
1906
|
-
function
|
|
1907
|
-
const { embeddings: embeddings3 } = tables3;
|
|
1908
|
-
const queryLiteral = formatEmbeddingLiteral(params.queryEmbedding);
|
|
1906
|
+
function assertVectorSearchBounds(params) {
|
|
1909
1907
|
if (params.minScore !== void 0 && !Number.isFinite(params.minScore)) {
|
|
1910
1908
|
throw new TypeError(
|
|
1911
1909
|
`minScore must be a finite number, got: ${params.minScore}`
|
|
@@ -1914,6 +1912,11 @@ function buildVectorSearchPostgres(tables3, params) {
|
|
|
1914
1912
|
if (!Number.isInteger(params.limit) || params.limit <= 0) {
|
|
1915
1913
|
throw new Error(`limit must be a positive integer, got: ${params.limit}`);
|
|
1916
1914
|
}
|
|
1915
|
+
}
|
|
1916
|
+
function buildVectorSearchPostgres(tables3, params) {
|
|
1917
|
+
const { embeddings: embeddings3 } = tables3;
|
|
1918
|
+
const queryLiteral = formatEmbeddingLiteral(params.queryEmbedding);
|
|
1919
|
+
assertVectorSearchBounds(params);
|
|
1917
1920
|
const embeddingColumn = sql`${embeddings3.embedding}`;
|
|
1918
1921
|
const distanceExpression = buildDistanceExpression(
|
|
1919
1922
|
embeddingColumn,
|
|
@@ -1949,6 +1952,65 @@ function buildVectorSearchPostgres(tables3, params) {
|
|
|
1949
1952
|
LIMIT ${params.limit}
|
|
1950
1953
|
`;
|
|
1951
1954
|
}
|
|
1955
|
+
function buildSqliteDistanceExpression(embeddingColumn, embeddingJson, metric) {
|
|
1956
|
+
switch (metric) {
|
|
1957
|
+
case "cosine": {
|
|
1958
|
+
return sql`vec_distance_cosine(${embeddingColumn}, vec_f32(${embeddingJson}))`;
|
|
1959
|
+
}
|
|
1960
|
+
case "l2": {
|
|
1961
|
+
return sql`vec_distance_l2(${embeddingColumn}, vec_f32(${embeddingJson}))`;
|
|
1962
|
+
}
|
|
1963
|
+
case "inner_product": {
|
|
1964
|
+
throw new Error(
|
|
1965
|
+
"Inner product distance is not supported by sqlite-vec. Use 'cosine' or 'l2' metrics instead."
|
|
1966
|
+
);
|
|
1967
|
+
}
|
|
1968
|
+
default: {
|
|
1969
|
+
const _exhaustive = metric;
|
|
1970
|
+
throw new Error(`Unsupported vector metric: ${String(_exhaustive)}`);
|
|
1971
|
+
}
|
|
1972
|
+
}
|
|
1973
|
+
}
|
|
1974
|
+
function buildVectorSearchSqlite(tables3, params) {
|
|
1975
|
+
const { embeddings: embeddings3 } = tables3;
|
|
1976
|
+
assertFiniteNumberArray(params.queryEmbedding, "queryEmbedding");
|
|
1977
|
+
const embeddingJson = JSON.stringify(params.queryEmbedding);
|
|
1978
|
+
assertVectorSearchBounds(params);
|
|
1979
|
+
const embeddingColumn = sql`${embeddings3.embedding}`;
|
|
1980
|
+
const distanceExpression = buildSqliteDistanceExpression(
|
|
1981
|
+
embeddingColumn,
|
|
1982
|
+
embeddingJson,
|
|
1983
|
+
params.metric
|
|
1984
|
+
);
|
|
1985
|
+
const conditions = [
|
|
1986
|
+
sql`${embeddings3.graphId} = ${params.graphId}`,
|
|
1987
|
+
sql`${embeddings3.nodeKind} = ${params.nodeKind}`,
|
|
1988
|
+
sql`${embeddings3.fieldPath} = ${params.fieldPath}`
|
|
1989
|
+
];
|
|
1990
|
+
if (params.minScore !== void 0) {
|
|
1991
|
+
conditions.push(
|
|
1992
|
+
buildVectorSearchMinScoreCondition(
|
|
1993
|
+
distanceExpression,
|
|
1994
|
+
params.metric,
|
|
1995
|
+
params.minScore
|
|
1996
|
+
)
|
|
1997
|
+
);
|
|
1998
|
+
}
|
|
1999
|
+
const whereClause = sql.join(conditions, sql` AND `);
|
|
2000
|
+
const scoreExpression = buildVectorSearchScoreExpression(
|
|
2001
|
+
distanceExpression,
|
|
2002
|
+
params.metric
|
|
2003
|
+
);
|
|
2004
|
+
return sql`
|
|
2005
|
+
SELECT
|
|
2006
|
+
${embeddings3.nodeId} as node_id,
|
|
2007
|
+
${scoreExpression} as score
|
|
2008
|
+
FROM ${embeddings3}
|
|
2009
|
+
WHERE ${whereClause}
|
|
2010
|
+
ORDER BY ${distanceExpression} ASC
|
|
2011
|
+
LIMIT ${params.limit}
|
|
2012
|
+
`;
|
|
2013
|
+
}
|
|
1952
2014
|
|
|
1953
2015
|
// src/backend/drizzle/operations/strategy.ts
|
|
1954
2016
|
function bindTableOperationBuilders(tables3, builders) {
|
|
@@ -2045,6 +2107,9 @@ function createSqliteOperationStrategy(tables3, fulltextStrategy) {
|
|
|
2045
2107
|
},
|
|
2046
2108
|
buildDeleteEmbedding(params) {
|
|
2047
2109
|
return buildDeleteEmbedding(tables3, params);
|
|
2110
|
+
},
|
|
2111
|
+
buildVectorSearch(params) {
|
|
2112
|
+
return buildVectorSearchSqlite(tables3, params);
|
|
2048
2113
|
}
|
|
2049
2114
|
};
|
|
2050
2115
|
}
|
|
@@ -2274,5 +2339,5 @@ function compileQueryWithDialect(db, query, backendName) {
|
|
|
2274
2339
|
}
|
|
2275
2340
|
|
|
2276
2341
|
export { POSTGRES_ROW_MAPPER_CONFIG, SQLITE_ROW_MAPPER_CONFIG, compileQueryWithDialect, createCommonOperationBackend, createEdgeRowMapper, createNodeRowMapper, createPostgresOperationStrategy, createPostgresTables, createPostgresVectorIndex, createSchemaVersionRowMapper, createSqliteOperationStrategy, createSqliteTables, createSqliteVectorIndex, createUniqueRowMapper, dropPostgresVectorIndex, dropSqliteVectorIndex, edges, edges2, embeddings, embeddings2, formatPostgresTimestamp, generatePostgresDDL, generatePostgresMigrationSQL, generateSqliteDDL, generateSqliteMigrationSQL, generateVectorIndexName, getOrCreateLru, nodes, nodes2, nowIso, schemaVersions, schemaVersions2, tables, tables2, uniques, uniques2 };
|
|
2277
|
-
//# sourceMappingURL=chunk-
|
|
2278
|
-
//# sourceMappingURL=chunk-
|
|
2342
|
+
//# sourceMappingURL=chunk-EY4LBX3F.js.map
|
|
2343
|
+
//# sourceMappingURL=chunk-EY4LBX3F.js.map
|