Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add rankingScoreThreshold to searchGet #1673

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/types/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,9 @@ export type SearchParams = Query &
vector?: number[] | null;
showRankingScore?: boolean;
showRankingScoreDetails?: boolean;
rankingScoreThreshold?: number;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just grouping the rankingScore stuff here for readibility :)

attributesToSearchOn?: string[] | null;
hybrid?: HybridSearch;
rankingScoreThreshold?: number;
};

// Search parameters for searches made with the GET method
Expand All @@ -147,6 +147,7 @@ export type SearchRequestGET = Pagination &
attributesToSearchOn?: string | null;
hybridEmbedder?: string;
hybridSemanticRatio?: number;
rankingScoreThreshold?: number;
};

export type MultiSearchQuery = SearchParams & { indexUid: string };
Expand Down
25 changes: 24 additions & 1 deletion tests/get_search.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -483,11 +483,34 @@ describe.each([

test(`${permission} key: search without vectors`, async () => {
const client = await getClient(permission);
const response = await client.index(index.uid).search('prince', {});
const response = await client.index(index.uid).searchGet('prince', {});
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixing a bad testing introduced earlier 🙈


expect(response).not.toHaveProperty('semanticHitCount');
});

test(`${permission} key: search with rankingScoreThreshold filter`, async () => {
const client = await getClient(permission);

const response = await client.index(index.uid).searchGet('prince', {
showRankingScore: true,
rankingScoreThreshold: 0.8,
});

const hit = response.hits[0];

expect(response).toHaveProperty('hits', expect.any(Array));
expect(response).toHaveProperty('query', 'prince');
expect(hit).toHaveProperty('_rankingScore');
expect(hit['_rankingScore']).toBeGreaterThanOrEqual(0.8);

const response2 = await client.index(index.uid).search('prince', {
showRankingScore: true,
rankingScoreThreshold: 0.9,
});

expect(response2.hits.length).toBeLessThanOrEqual(0);
});

test(`${permission} key: Try to search on deleted index and fail`, async () => {
const client = await getClient(permission);
const masterClient = await getClient('Master');
Expand Down