Skip to content

Commit 00a5abd

Browse files
fix: reviewer feedback – sparse index default, single sparse ref, clampTopK, keyword_search normalization
1 parent e44291e commit 00a5abd

2 files changed

Lines changed: 22 additions & 7 deletions

File tree

src/pinecone-client.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,9 @@ export class PineconeClient {
8484
* Normalize and clamp topK from request (validates >= 1, caps at MAX_TOP_K).
8585
*/
8686
private clampTopK(requested: number | undefined): number {
87+
if (requested !== undefined && !Number.isFinite(requested)) {
88+
throw new Error('topK must be a finite number >= 1');
89+
}
8790
let topK = requested !== undefined ? requested : this.defaultTopK;
8891
if (topK < 1) {
8992
throw new Error('topK must be at least 1');
@@ -123,7 +126,7 @@ export class PineconeClient {
123126

124127
const pc = this.ensureClient();
125128
const denseName = this.indexName;
126-
const sparseName = `${this.indexName}-sparse`;
129+
const sparseName = this.getSparseIndexName();
127130

128131
const dense = pc.index(denseName) as unknown as SearchableIndex;
129132
const sparse = pc.index(sparseName) as unknown as SearchableIndex;

src/server/tools/keyword-search-tool.ts

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,23 @@ async function executeKeywordSearch(params: {
3838
}): Promise<KeywordSearchResponse> {
3939
const { query_text, namespace, top_k, metadata_filter, fields } = params;
4040

41-
if (!query_text.trim()) {
41+
const normalizedQuery = query_text.trim();
42+
const normalizedNamespace = namespace?.trim() ?? '';
43+
44+
if (!normalizedQuery) {
4245
return {
4346
status: 'error',
4447
message: 'Query text cannot be empty',
4548
};
4649
}
4750

51+
if (!normalizedNamespace) {
52+
return {
53+
status: 'error',
54+
message: 'Namespace cannot be empty',
55+
};
56+
}
57+
4858
if (metadata_filter) {
4959
const filterError = validateMetadataFilter(metadata_filter);
5060
if (filterError) {
@@ -54,19 +64,21 @@ async function executeKeywordSearch(params: {
5464

5565
const client = getPineconeClient();
5666
const results = await client.keywordSearch({
57-
query: query_text.trim(),
58-
namespace,
67+
query: normalizedQuery,
68+
namespace: normalizedNamespace,
5969
topK: top_k,
6070
metadataFilter: metadata_filter,
6171
fields: fields?.length ? fields : undefined,
6272
});
6373

64-
const formattedResults = formatQueryResultRows(results, { namespace });
74+
const formattedResults = formatQueryResultRows(results, {
75+
namespace: normalizedNamespace,
76+
});
6577

6678
const response: KeywordSearchResponse = {
6779
status: 'success',
68-
query: query_text,
69-
namespace,
80+
query: normalizedQuery,
81+
namespace: normalizedNamespace,
7082
index: client.getSparseIndexName(),
7183
metadata_filter: metadata_filter,
7284
result_count: formattedResults.length,

0 commit comments

Comments
 (0)