perf: Optimize document filtering and sorting for performance

This commit is contained in:
Zan 2024-07-23 10:06:33 +08:00
parent c0b3a409dd
commit 323f3c516c
3 changed files with 9 additions and 9 deletions

View File

@ -177,9 +177,9 @@ const createBasicRedditSearchAnsweringChain = (
});
const sortedDocs = similarity
.filter((sim) => sim.similarity > 0.3)
.sort((a, b) => b.similarity - a.similarity)
.slice(0, 15)
.filter((sim) => sim.similarity > 0.3)
.map((sim) => docsWithContent[sim.index]);
return sortedDocs;

View File

@ -175,8 +175,8 @@ const createBasicWebSearchAnsweringChain = (
});
const sortedDocs = similarity
.sort((a, b) => b.similarity - a.similarity)
.filter((sim) => sim.similarity > 0.5)
.sort((a, b) => b.similarity - a.similarity)
.slice(0, 15)
.map((sim) => docsWithContent[sim.index]);

View File

@ -177,9 +177,9 @@ const createBasicYoutubeSearchAnsweringChain = (
});
const sortedDocs = similarity
.filter((sim) => sim.similarity > 0.3)
.sort((a, b) => b.similarity - a.similarity)
.slice(0, 15)
.filter((sim) => sim.similarity > 0.3)
.map((sim) => docsWithContent[sim.index]);
return sortedDocs;