This commit is contained in:
parent
1730caf144
commit
36c57c6a41
|
|
@ -145,10 +145,33 @@ export async function POST(req: Request) {
|
||||||
} else if (embeddingsProvider === "bge-m3"){
|
} else if (embeddingsProvider === "bge-m3"){
|
||||||
|
|
||||||
// 示例:调用你自己的 BGE-M3 API 或本地函数
|
// 示例:调用你自己的 BGE-M3 API 或本地函数
|
||||||
const embeddingPromises = chunks.map(async chunk => {
|
// const embeddingPromises = chunks.map(async chunk => {
|
||||||
|
const embeddingPromises = chunks.map(async (chunk, index) => {
|
||||||
try {
|
try {
|
||||||
return await generateBgeM3Embedding(chunk.content)
|
// return await generateBgeM3Embedding(chunk.content)
|
||||||
|
|
||||||
|
const result = await generateBgeM3Embedding(chunk.content)
|
||||||
|
|
||||||
|
if (!Array.isArray(result)) {
|
||||||
|
console.error(`......❌ Chunk ${index}: result is not an array`, result)
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
|
if (result.length !== 1024) {
|
||||||
|
console.error(`......❌ Chunk ${index}: incorrect length: ${result.length}`)
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!result.every(x => typeof x === "number")) {
|
||||||
|
console.error(`......❌ Chunk ${index}: contains non-numbers`, result)
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
|
return result
|
||||||
|
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|
||||||
console.error(`Error generating BGE-M3 embedding for chunk: ${chunk}`, error)
|
console.error(`Error generating BGE-M3 embedding for chunk: ${chunk}`, error)
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
@ -171,7 +194,7 @@ export async function POST(req: Request) {
|
||||||
? ((embeddings[index] || null) as any)
|
? ((embeddings[index] || null) as any)
|
||||||
: null,
|
: null,
|
||||||
bge_m3_embedding:
|
bge_m3_embedding:
|
||||||
embeddingsProvider === "bge-m3"
|
embeddingsProvider === "bge-m3" && embeddings[index] && embeddings[index].length === 1024
|
||||||
? (embeddings[index] || null) as any
|
? (embeddings[index] || null) as any
|
||||||
: null
|
: null
|
||||||
}))
|
}))
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue