Skip to content

Commit

Permalink
(DOCSP-32868): only boost 2 results + order results by score (#130)
Browse files Browse the repository at this point in the history
* only boost 2 results + order results by score

* sort before slice
  • Loading branch information
mongodben authored Sep 1, 2023
1 parent 94e8a20 commit 5230992
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 17 deletions.
2 changes: 1 addition & 1 deletion chat-server/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export const boostManual = makeBoostOnAtlasSearchFilter({
query: "snooty-docs",
},
},
k: 3,
k: 2,
minScore: 0.88,
},
totalMaxK: 5,
Expand Down
21 changes: 6 additions & 15 deletions chat-server/src/processors/makeBoostOnAtlasSearchFilter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ describe("makeBoostOnAtlasSearchFilter()", () => {
return text.split(" ").filter((s) => s !== " ").length <= 3;
},
findNearestNeighborsOptions: {
k: 3,
k: 2,
filter: {
text: {
path: "sourceName",
Expand Down Expand Up @@ -97,16 +97,6 @@ describe("makeBoostOnAtlasSearchFilter()", () => {
sourceName: "not-snooty-docs", // only important value
score: 0.95,
},
{
_id: new ObjectId(),
url: "https://mongodb.com/docs/",
text: "everything you own in a box to the left",
tokenCount: 100,
embedding: [0.1, 0.2, 0.3],
updated: new Date(),
sourceName: "not-snooty-docs", // only important value
score: 0.95,
},
];
const embedding = [0.1, 0.2, 0.3];
test("Boosts manual results", async () => {
Expand All @@ -115,11 +105,12 @@ describe("makeBoostOnAtlasSearchFilter()", () => {
existingResults,
store: mockStore,
});
// expect(results).toHaveLength(5);
expect(results[0]).toStrictEqual(sharedResult);
expect(results[1]).toStrictEqual(mockBoostedResults[1]);
expect(results[2]).toStrictEqual(existingResults[0]);
expect(results).toHaveLength(5);
expect(results[0]).toStrictEqual(existingResults[0]);
expect(results[1]).toStrictEqual(sharedResult);
expect(results[2]).toStrictEqual(existingResults[2]);
expect(results[3]).toStrictEqual(existingResults[3]);
expect(results[4]).toStrictEqual(mockBoostedResults[1]);
});
});
});
4 changes: 3 additions & 1 deletion chat-server/src/processors/makeBoostOnAtlasSearchFilter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ export function makeBoostOnAtlasSearchFilter({
(manualResult) => manualResult.text !== result.text
)
);
return [...boostedResults, ...newResults].slice(0, totalMaxK);
return [...boostedResults, ...newResults]
.sort((a, b) => b.score - a.score)
.slice(0, totalMaxK);
},
};
}

0 comments on commit 5230992

Please sign in to comment.