fix(memory-lancedb): pass dimensions to embedding API call

- Add dimensions parameter to Embeddings constructor
- Pass dimensions to OpenAI embeddings.create() API call
- Fixes dimension mismatch when using custom embedding models like DashScope text-embedding-v4
This commit is contained in:
scotthuang
2026-03-03 01:59:06 +08:00
committed by Peter Steinberger
parent c146748d7a
commit 31bc2cc202

View File

@@ -167,15 +167,20 @@ class Embeddings {
apiKey: string,
private model: string,
baseUrl?: string,
private dimensions?: number,
) {
this.client = new OpenAI({ apiKey, baseURL: baseUrl });
}
async embed(text: string): Promise<number[]> {
const response = await this.client.embeddings.create({
const params: { model: string; input: string; dimensions?: number } = {
model: this.model,
input: text,
});
};
if (this.dimensions) {
params.dimensions = this.dimensions;
}
const response = await this.client.embeddings.create(params);
return response.data[0].embedding;
}
}
@@ -298,7 +303,7 @@ const memoryPlugin = {
const vectorDim = dimensions ?? vectorDimsForModel(model);
const db = new MemoryDB(resolvedDbPath, vectorDim);
const embeddings = new Embeddings(apiKey, model, baseUrl);
const embeddings = new Embeddings(apiKey, model, baseUrl, dimensions);
api.logger.info(`memory-lancedb: plugin registered (db: ${resolvedDbPath}, lazy init)`);