fix(node): select auto search from table metadata

This commit is contained in:
Gatefixer
2026-08-08 12:34:43 +00:00
parent 4dd31b4207
commit cdbf6e1029
4 changed files with 34 additions and 9 deletions
@@ -9,6 +9,8 @@ const { getRegistry } = require("../../dist/embedding/registry");
async function main() {
assert.equal(typeof embedding.getRegistry, "function");
assert.equal(getRegistry().length(), 0);
assert.equal(embedding.getRegistry(), getRegistry());
assert.equal(getRegistry().length(), 2);
const dir = tmp.dirSync({ unsafeCleanup: true });
let db;
+4 -4
View File
@@ -535,7 +535,7 @@ export class LocalConnection extends Connection {
options?.indexCacheSize,
);
let table: Table = new LocalTable(innerTable);
let table: Table = await LocalTable.create(innerTable);
// "main" is the default branch, so treat it as no branch. On a real branch,
// scope and pin in one step (yielding "version V of branch B"); otherwise
// pin the version, if any, against main.
@@ -570,7 +570,7 @@ export class LocalConnection extends Connection {
options?.isShallow ?? true,
);
return new LocalTable(innerTable);
return LocalTable.create(innerTable);
}
private getStorageOptions(
@@ -652,7 +652,7 @@ export class LocalConnection extends Connection {
storageOptions,
);
return new LocalTable(innerTable);
return LocalTable.create(innerTable);
}
async createEmptyTable(
@@ -698,7 +698,7 @@ export class LocalConnection extends Connection {
namespacePath ?? [],
storageOptions,
);
return new LocalTable(innerTable);
return LocalTable.create(innerTable);
}
async dropTable(name: string, namespacePath?: string[]): Promise<void> {
+1 -1
View File
@@ -172,7 +172,7 @@ export class PermutationBuilder {
*/
async execute(): Promise<Table> {
const nativeTable: NativeTable = await this.inner.execute();
return new LocalTable(nativeTable);
return LocalTable.create(nativeTable);
}
}
+27 -4
View File
@@ -814,10 +814,31 @@ export abstract class Table {
export class LocalTable extends Table {
private readonly inner: _NativeTable;
private readonly hasEmbeddingFunctions: boolean;
constructor(inner: _NativeTable) {
private constructor(inner: _NativeTable, hasEmbeddingFunctions: boolean) {
super();
this.inner = inner;
this.hasEmbeddingFunctions = hasEmbeddingFunctions;
}
/** @hidden */
static async create(inner: _NativeTable): Promise<LocalTable> {
const schemaBuf = await inner.schema();
const schema = tableFromIPC(schemaBuf).schema;
const serializedFunctions = schema.metadata.get("embedding_functions");
if (serializedFunctions === undefined) {
return new LocalTable(inner, false);
}
let hasEmbeddingFunctions = true;
try {
const functions = JSON.parse(serializedFunctions);
hasEmbeddingFunctions = !Array.isArray(functions) || functions.length > 0;
} catch {
// Preserve the existing parse error when the search is executed.
}
return new LocalTable(inner, hasEmbeddingFunctions);
}
get name(): string {
return this.inner.name;
@@ -1038,7 +1059,7 @@ export class LocalTable extends Table {
// fall back to full text search if no embedding functions are defined and the query is a string
if (
queryType === "auto" &&
(getRegistry().length() === 0 || instanceOfFullTextQuery(query))
(!this.hasEmbeddingFunctions || instanceOfFullTextQuery(query))
) {
return this.query().fullTextSearch(query, {
columns: ftsColumns,
@@ -1461,7 +1482,9 @@ export class Branches {
fromRef?: string,
fromVersion?: number,
): Promise<Table> {
return new LocalTable(await this.#inner.create(name, fromRef, fromVersion));
return LocalTable.create(
await this.#inner.create(name, fromRef, fromVersion),
);
}
/**
@@ -1472,7 +1495,7 @@ export class Branches {
* latest and stays writable.
*/
async checkout(name: string, version?: number): Promise<Table> {
return new LocalTable(await this.#inner.checkout(name, version));
return LocalTable.create(await this.#inner.checkout(name, version));
}
/** Delete a branch. */