|
|
@@ -1414,6 +1414,7 @@ export async function generateEmbeddings(
|
|
|
|
|
|
// Use store's LlamaCpp or global singleton, wrapped in a session
|
|
|
const llm = getLlm(store);
|
|
|
+ const embedModelUri = llm.embedModelName;
|
|
|
|
|
|
// Create a session manager for this llm instance
|
|
|
const result = await withLLMSessionForLlm(llm, async (session) => {
|
|
|
@@ -1471,7 +1472,7 @@ export async function generateEmbeddings(
|
|
|
|
|
|
if (!vectorTableInitialized) {
|
|
|
const firstChunk = batchChunks[0]!;
|
|
|
- const firstText = formatDocForEmbedding(firstChunk.text, firstChunk.title, model);
|
|
|
+ const firstText = formatDocForEmbedding(firstChunk.text, firstChunk.title, embedModelUri);
|
|
|
const firstResult = await session.embed(firstText, { model });
|
|
|
if (!firstResult) {
|
|
|
throw new Error("Failed to get embedding dimensions from first chunk");
|
|
|
@@ -1503,7 +1504,7 @@ export async function generateEmbeddings(
|
|
|
|
|
|
const batchEnd = Math.min(batchStart + BATCH_SIZE, batchChunks.length);
|
|
|
const chunkBatch = batchChunks.slice(batchStart, batchEnd);
|
|
|
- const texts = chunkBatch.map(chunk => formatDocForEmbedding(chunk.text, chunk.title, model));
|
|
|
+ const texts = chunkBatch.map(chunk => formatDocForEmbedding(chunk.text, chunk.title, embedModelUri));
|
|
|
|
|
|
try {
|
|
|
const embeddings = await session.embedBatch(texts, { model });
|
|
|
@@ -1527,7 +1528,7 @@ export async function generateEmbeddings(
|
|
|
} else {
|
|
|
for (const chunk of chunkBatch) {
|
|
|
try {
|
|
|
- const text = formatDocForEmbedding(chunk.text, chunk.title, model);
|
|
|
+ const text = formatDocForEmbedding(chunk.text, chunk.title, embedModelUri);
|
|
|
const result = await session.embed(text, { model });
|
|
|
if (result) {
|
|
|
insertEmbedding(db, chunk.hash, chunk.seq, chunk.pos, new Float32Array(result.embedding), model, now);
|
|
|
@@ -3985,7 +3986,7 @@ export async function hybridQuery(
|
|
|
|
|
|
// Batch embed all vector queries in a single call
|
|
|
const llm = getLlm(store);
|
|
|
- const textsToEmbed = vecQueries.map(q => formatQueryForEmbedding(q.text));
|
|
|
+ const textsToEmbed = vecQueries.map(q => formatQueryForEmbedding(q.text, llm.embedModelName));
|
|
|
hooks?.onEmbedStart?.(textsToEmbed.length);
|
|
|
const embedStart = Date.now();
|
|
|
const embeddings = await llm.embedBatch(textsToEmbed);
|
|
|
@@ -4368,7 +4369,7 @@ export async function structuredSearch(
|
|
|
);
|
|
|
if (vecSearches.length > 0) {
|
|
|
const llm = getLlm(store);
|
|
|
- const textsToEmbed = vecSearches.map(s => formatQueryForEmbedding(s.query));
|
|
|
+ const textsToEmbed = vecSearches.map(s => formatQueryForEmbedding(s.query, llm.embedModelName));
|
|
|
hooks?.onEmbedStart?.(textsToEmbed.length);
|
|
|
const embedStart = Date.now();
|
|
|
const embeddings = await llm.embedBatch(textsToEmbed);
|