mirror of
https://github.com/garrytan/gbrain.git
synced 2026-07-31 04:07:52 +00:00
fix(types): doctor 8b uses portable executeRaw + Voyage fetch-shim cast
#665's doctor 8b dim-probe used `engine.sql\`...\`` directly (Postgres template literal) which doesn't typecheck against the BrainEngine interface (only PostgresEngine has the .sql getter; PGLite does not). Refactored to use `readContentChunksEmbeddingDim` from src/core/embedding-dim-check.ts — same helper init's A4 hard-error path uses, runs portably on both engines. #680's Voyage fetch-shim passes a custom fetch handler to `createOpenAICompatible` for the encoding_format + prompt_tokens normalization. The SDK accepts the field at runtime but the typed parameter on the pinned version doesn't expose it. Cast to the parameter type so the shim ships without a type error. Both fixes are mechanical cleanup of cherry-picked PRs that didn't typecheck against current master's stricter shape. No behavior change. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.7
parent
a5e6d09938
commit
4c26e4845b
@@ -607,17 +607,15 @@ export async function runDoctor(engine: BrainEngine | null, args: string[], dbSo
|
|||||||
issues.push(`Dimension mismatch: provider returned ${actualDims} but config expects ${configuredDims}`);
|
issues.push(`Dimension mismatch: provider returned ${actualDims} but config expects ${configuredDims}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check DB column dimensions match
|
// Check DB column dimensions match (engine-portable; works on both
|
||||||
|
// Postgres and PGLite via the shared dim-check helper added in v0.28.5).
|
||||||
try {
|
try {
|
||||||
const dbDimRow = await engine.sql`
|
const { readContentChunksEmbeddingDim } = await import('../core/embedding-dim-check.ts');
|
||||||
SELECT vector_dims(embedding) as dims
|
const colDim = await readContentChunksEmbeddingDim(engine);
|
||||||
FROM content_chunks
|
if (colDim.exists && colDim.dims !== null && colDim.dims !== actualDims) {
|
||||||
WHERE embedding IS NOT NULL
|
issues.push(`DB dimension mismatch: column is vector(${colDim.dims}) but provider returns ${actualDims}-dim. See docs/embedding-migrations.md for the manual ALTER recipe.`);
|
||||||
LIMIT 1`;
|
|
||||||
if (dbDimRow.length > 0 && dbDimRow[0].dims !== actualDims) {
|
|
||||||
issues.push(`DB dimension mismatch: stored vectors are ${dbDimRow[0].dims}-dim but provider returns ${actualDims}-dim. Migration needed.`);
|
|
||||||
}
|
}
|
||||||
} catch { /* no chunks with embeddings yet, that's fine */ }
|
} catch { /* column or table missing — fresh brain, fine */ }
|
||||||
|
|
||||||
if (issues.length > 0) {
|
if (issues.length > 0) {
|
||||||
checks.push({
|
checks.push({
|
||||||
|
|||||||
@@ -229,12 +229,15 @@ function instantiateEmbedding(recipe: Recipe, modelId: string, cfg: AIGatewayCon
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
: undefined;
|
: undefined;
|
||||||
|
// SDK accepts a `fetch` override at runtime but the typed settings don't
|
||||||
|
// expose it on this version pin; cast so v0.28.5's #680 fetch-shim
|
||||||
|
// (Voyage encoding_format + usage normalization) typechecks.
|
||||||
const client = createOpenAICompatible({
|
const client = createOpenAICompatible({
|
||||||
name: recipe.id,
|
name: recipe.id,
|
||||||
baseURL: baseUrl,
|
baseURL: baseUrl,
|
||||||
apiKey: apiKey ?? 'unauthenticated',
|
apiKey: apiKey ?? 'unauthenticated',
|
||||||
...(voyageFetch ? { fetch: voyageFetch } : {}),
|
...(voyageFetch ? { fetch: voyageFetch } : {}),
|
||||||
});
|
} as Parameters<typeof createOpenAICompatible>[0]);
|
||||||
return client.textEmbeddingModel(modelId);
|
return client.textEmbeddingModel(modelId);
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
|
|||||||
Reference in New Issue
Block a user