fix: harden AI analysis provider responses
This commit is contained in:
@@ -125,8 +125,12 @@ async function buildKnowledgeChunks(input: KnowledgeEntryInput): Promise<Service
|
||||
}
|
||||
|
||||
const chunks = chunkKnowledgeText(input);
|
||||
const vectors = await embeddingsResult.embeddings.embedDocuments(chunks);
|
||||
return { success: true, data: { chunks, vectors } };
|
||||
try {
|
||||
const vectors = await embeddingsResult.embeddings.embedDocuments(chunks);
|
||||
return { success: true, data: { chunks, vectors } };
|
||||
} catch {
|
||||
return { success: false, reason: "知识库向量生成失败", status: 500 };
|
||||
}
|
||||
}
|
||||
|
||||
export async function listKnowledgeEntries(context: AuthContext): Promise<KnowledgeEntry[]> {
|
||||
@@ -214,15 +218,15 @@ async function updateEntryWithChunks(
|
||||
const rows = await transaction
|
||||
.update(aiKnowledgeEntries)
|
||||
.set({
|
||||
scope: input.scope,
|
||||
organizationId,
|
||||
title: input.title,
|
||||
category: input.category,
|
||||
tags: input.tags,
|
||||
body: input.body,
|
||||
status: input.status,
|
||||
updatedByAccountId: context.account.id,
|
||||
updatedAt: new Date(),
|
||||
scope: input.scope,
|
||||
organizationId,
|
||||
title: input.title,
|
||||
category: input.category,
|
||||
tags: input.tags,
|
||||
body: input.body,
|
||||
status: input.status,
|
||||
updatedByAccountId: context.account.id,
|
||||
updatedAt: new Date(),
|
||||
})
|
||||
.where(eq(aiKnowledgeEntries.id, id))
|
||||
.returning();
|
||||
@@ -322,7 +326,8 @@ export async function retrieveKnowledge(
|
||||
return { success: false, reason: embeddingsResult.reason, status: 500 };
|
||||
}
|
||||
|
||||
const [embedding] = await embeddingsResult.embeddings.embedDocuments([query]);
|
||||
const vectors = await embeddingsResult.embeddings.embedDocuments([query]).catch(() => []);
|
||||
const embedding = vectors[0];
|
||||
if (!embedding) {
|
||||
return { success: false, reason: "知识库向量生成失败", status: 500 };
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user