mirror of
https://github.com/labring/FastGPT.git
synced 2025-07-24 22:03:54 +00:00
feat: normalization embedding;feat: model top_p param config (#3723)
* edit form force close image select * model config * feat: normalization embedding * perf: add share page title force refresh
This commit is contained in:
@@ -56,7 +56,14 @@ export async function getVectorsByText({ model, input, type }: GetVectorProps) {
|
||||
|
||||
const [tokens, vectors] = await Promise.all([
|
||||
countPromptTokens(input),
|
||||
Promise.all(res.data.map((item) => unityDimensional(item.embedding)))
|
||||
Promise.all(
|
||||
res.data
|
||||
.map((item) => unityDimensional(item.embedding))
|
||||
.map((item) => {
|
||||
if (model.normalization) return normalization(item);
|
||||
return item;
|
||||
})
|
||||
)
|
||||
]);
|
||||
|
||||
return {
|
||||
@@ -87,3 +94,15 @@ function unityDimensional(vector: number[]) {
|
||||
|
||||
return resultVector.concat(zeroVector);
|
||||
}
|
||||
// normalization processing
|
||||
function normalization(vector: number[]) {
|
||||
if (vector.some((item) => item > 1)) {
|
||||
// Calculate the Euclidean norm (L2 norm)
|
||||
const norm = Math.sqrt(vector.reduce((sum, val) => sum + val * val, 0));
|
||||
|
||||
// Normalize the vector by dividing each component by the norm
|
||||
return vector.map((val) => val / norm);
|
||||
}
|
||||
|
||||
return vector;
|
||||
}
|
||||
|
Reference in New Issue
Block a user