@ontos-ai/knowhere-sdk 2.2.0-beta.20260716073420 → 2.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +7 -1
- package/dist/index.d.mts +9 -1
- package/dist/index.d.ts +9 -1
- package/dist/index.js +22 -41
- package/dist/index.mjs +22 -41
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -423,6 +423,7 @@ const grep = await client.knowledge.grepChunks({
|
|
|
423
423
|
pattern: 'warranty',
|
|
424
424
|
maxResults: 10,
|
|
425
425
|
});
|
|
426
|
+
// grep.matches include pageNumbers when the source chunk has them.
|
|
426
427
|
|
|
427
428
|
const serverSearch = await client.knowledge.search({
|
|
428
429
|
query: 'battery warranty',
|
|
@@ -514,12 +515,17 @@ without creating SDK local-disk cache state. Use `syncParsedDocument(...)` to
|
|
|
514
515
|
explicitly resume or retry parsed-storage sync for an existing `documentId`,
|
|
515
516
|
`jobId`, or local parsed result.
|
|
516
517
|
|
|
517
|
-
|
|
518
|
+
Retrieval queries can limit documents and exclude documents or sections for one request.
|
|
519
|
+
`includeDocumentIds?: string[]` restricts retrieval to the supplied document IDs.
|
|
520
|
+
Omitting it leaves documents unrestricted by inclusion; passing `[]` matches no
|
|
521
|
+
documents. Exclusions take precedence over inclusions, including when a document
|
|
522
|
+
ID appears in both `includeDocumentIds` and `excludeDocumentIds`.
|
|
518
523
|
|
|
519
524
|
```typescript
|
|
520
525
|
const followUp = await client.retrieval.query({
|
|
521
526
|
namespace: 'support-center',
|
|
522
527
|
query: 'battery charging',
|
|
528
|
+
includeDocumentIds: ['doc_123', 'doc_old'],
|
|
523
529
|
excludeDocumentIds: ['doc_old'],
|
|
524
530
|
excludeSections: [{ documentId: 'doc_123', sectionPath: 'Appendix / Legal' }],
|
|
525
531
|
});
|
package/dist/index.d.mts
CHANGED
|
@@ -859,7 +859,13 @@ interface RetrievalQueryParams {
|
|
|
859
859
|
threshold?: number;
|
|
860
860
|
/** Override the internal per-channel recall count */
|
|
861
861
|
internalRecallK?: number;
|
|
862
|
-
/**
|
|
862
|
+
/**
|
|
863
|
+
* Limit retrieval to these documents for this request only.
|
|
864
|
+
* Omitted means no document inclusion restriction; [] matches no documents.
|
|
865
|
+
* Exclusions take precedence over inclusions.
|
|
866
|
+
*/
|
|
867
|
+
includeDocumentIds?: string[];
|
|
868
|
+
/** Documents to exclude for this request only, even when included in includeDocumentIds. */
|
|
863
869
|
excludeDocumentIds?: string[];
|
|
864
870
|
/** Document sections to exclude for this request only */
|
|
865
871
|
excludeSections?: RetrievalSectionExclusion[];
|
|
@@ -1355,6 +1361,8 @@ interface KnowledgeGrepMatch {
|
|
|
1355
1361
|
startOffset: number;
|
|
1356
1362
|
endOffset: number;
|
|
1357
1363
|
snippet: string;
|
|
1364
|
+
/** Copied from the source chunk when the indexed chunk has page numbers. */
|
|
1365
|
+
pageNumbers?: number[];
|
|
1358
1366
|
}
|
|
1359
1367
|
interface KnowledgeGrepResponse {
|
|
1360
1368
|
document: LocalKnowledgeDocument;
|
package/dist/index.d.ts
CHANGED
|
@@ -859,7 +859,13 @@ interface RetrievalQueryParams {
|
|
|
859
859
|
threshold?: number;
|
|
860
860
|
/** Override the internal per-channel recall count */
|
|
861
861
|
internalRecallK?: number;
|
|
862
|
-
/**
|
|
862
|
+
/**
|
|
863
|
+
* Limit retrieval to these documents for this request only.
|
|
864
|
+
* Omitted means no document inclusion restriction; [] matches no documents.
|
|
865
|
+
* Exclusions take precedence over inclusions.
|
|
866
|
+
*/
|
|
867
|
+
includeDocumentIds?: string[];
|
|
868
|
+
/** Documents to exclude for this request only, even when included in includeDocumentIds. */
|
|
863
869
|
excludeDocumentIds?: string[];
|
|
864
870
|
/** Document sections to exclude for this request only */
|
|
865
871
|
excludeSections?: RetrievalSectionExclusion[];
|
|
@@ -1355,6 +1361,8 @@ interface KnowledgeGrepMatch {
|
|
|
1355
1361
|
startOffset: number;
|
|
1356
1362
|
endOffset: number;
|
|
1357
1363
|
snippet: string;
|
|
1364
|
+
/** Copied from the source chunk when the indexed chunk has page numbers. */
|
|
1365
|
+
pageNumbers?: number[];
|
|
1358
1366
|
}
|
|
1359
1367
|
interface KnowledgeGrepResponse {
|
|
1360
1368
|
document: LocalKnowledgeDocument;
|
package/dist/index.js
CHANGED
|
@@ -2614,17 +2614,7 @@ var Knowledge = class _Knowledge {
|
|
|
2614
2614
|
scannedChunks += 1;
|
|
2615
2615
|
const chunkMatches = matcher(chunk.content);
|
|
2616
2616
|
for (const match of chunkMatches) {
|
|
2617
|
-
matches.push(
|
|
2618
|
-
position: chunk.position,
|
|
2619
|
-
chunkId: chunk.chunkId,
|
|
2620
|
-
chunkType: chunk.chunkType,
|
|
2621
|
-
sectionPath: chunk.sectionPath,
|
|
2622
|
-
sourceChunkPath: chunk.sourceChunkPath,
|
|
2623
|
-
filePath: chunk.filePath,
|
|
2624
|
-
startOffset: match.startOffset,
|
|
2625
|
-
endOffset: match.endOffset,
|
|
2626
|
-
snippet: buildSnippet(chunk.content, match.startOffset, match.endOffset, contextChars)
|
|
2627
|
-
});
|
|
2617
|
+
matches.push(toGrepMatch(chunk, match, contextChars));
|
|
2628
2618
|
if (matches.length >= maxResults) {
|
|
2629
2619
|
return { document, matches, scannedChunks, truncated: true };
|
|
2630
2620
|
}
|
|
@@ -2638,7 +2628,8 @@ var Knowledge = class _Knowledge {
|
|
|
2638
2628
|
query: params.query,
|
|
2639
2629
|
namespace: params.namespace,
|
|
2640
2630
|
topK: params.topK,
|
|
2641
|
-
|
|
2631
|
+
// Omit when undefined so the API default (map-nav) applies; false → classic.
|
|
2632
|
+
useAgentic: params.useAgentic
|
|
2642
2633
|
});
|
|
2643
2634
|
const documentByServerId = new Map(
|
|
2644
2635
|
localDocuments.filter((document) => document.documentId).map((document) => [document.documentId, document])
|
|
@@ -2855,31 +2846,17 @@ var Knowledge = class _Knowledge {
|
|
|
2855
2846
|
if (response.pagination.page === startPage && cursor?.nextChunkIndex !== void 0 && chunkIndex < cursor.nextChunkIndex) {
|
|
2856
2847
|
continue;
|
|
2857
2848
|
}
|
|
2858
|
-
|
|
2849
|
+
const indexed = toIndexedRemoteChunk(chunk);
|
|
2850
|
+
if (!matchesGrepScope(indexed, params)) {
|
|
2859
2851
|
continue;
|
|
2860
2852
|
}
|
|
2861
2853
|
scannedChunks += 1;
|
|
2862
|
-
const chunkMatches = matcher(
|
|
2854
|
+
const chunkMatches = matcher(indexed.content);
|
|
2863
2855
|
for (const [matchIndex, match] of chunkMatches.entries()) {
|
|
2864
2856
|
if (response.pagination.page === startPage && cursor?.nextChunkIndex === chunkIndex && cursor.nextMatchIndex !== void 0 && matchIndex < cursor.nextMatchIndex) {
|
|
2865
2857
|
continue;
|
|
2866
2858
|
}
|
|
2867
|
-
matches.push(
|
|
2868
|
-
position: toChunkPosition(chunk),
|
|
2869
|
-
chunkId: chunk.chunkId,
|
|
2870
|
-
chunkType: chunk.chunkType,
|
|
2871
|
-
sectionPath: chunk.sectionPath ?? "",
|
|
2872
|
-
sourceChunkPath: chunk.sourceChunkPath ?? chunk.sectionPath ?? "",
|
|
2873
|
-
filePath: chunk.filePath ?? void 0,
|
|
2874
|
-
startOffset: match.startOffset,
|
|
2875
|
-
endOffset: match.endOffset,
|
|
2876
|
-
snippet: buildSnippet(
|
|
2877
|
-
chunk.content ?? "",
|
|
2878
|
-
match.startOffset,
|
|
2879
|
-
match.endOffset,
|
|
2880
|
-
contextChars
|
|
2881
|
-
)
|
|
2882
|
-
});
|
|
2859
|
+
matches.push(toGrepMatch(indexed, match, contextChars));
|
|
2883
2860
|
if (matches.length >= maxResults) {
|
|
2884
2861
|
const continuationCursor = createGrepContinuationCursor({
|
|
2885
2862
|
documentId,
|
|
@@ -3043,17 +3020,7 @@ var Knowledge = class _Knowledge {
|
|
|
3043
3020
|
for (const chunk of scopedChunks) {
|
|
3044
3021
|
scannedChunks += 1;
|
|
3045
3022
|
for (const match of matcher(chunk.content)) {
|
|
3046
|
-
matches.push(
|
|
3047
|
-
position: chunk.position,
|
|
3048
|
-
chunkId: chunk.chunkId,
|
|
3049
|
-
chunkType: chunk.chunkType,
|
|
3050
|
-
sectionPath: chunk.sectionPath,
|
|
3051
|
-
sourceChunkPath: chunk.sourceChunkPath,
|
|
3052
|
-
filePath: chunk.filePath,
|
|
3053
|
-
startOffset: match.startOffset,
|
|
3054
|
-
endOffset: match.endOffset,
|
|
3055
|
-
snippet: buildSnippet(chunk.content, match.startOffset, match.endOffset, contextChars)
|
|
3056
|
-
});
|
|
3023
|
+
matches.push(toGrepMatch(chunk, match, contextChars));
|
|
3057
3024
|
if (matches.length >= maxResults) {
|
|
3058
3025
|
return {
|
|
3059
3026
|
document: createStoredKnowledgeDocument({
|
|
@@ -4083,6 +4050,20 @@ function toReadChunk(chunk) {
|
|
|
4083
4050
|
metadata: chunk.metadata
|
|
4084
4051
|
};
|
|
4085
4052
|
}
|
|
4053
|
+
function toGrepMatch(chunk, match, contextChars) {
|
|
4054
|
+
return {
|
|
4055
|
+
position: chunk.position,
|
|
4056
|
+
chunkId: chunk.chunkId,
|
|
4057
|
+
chunkType: chunk.chunkType,
|
|
4058
|
+
sectionPath: chunk.sectionPath,
|
|
4059
|
+
sourceChunkPath: chunk.sourceChunkPath,
|
|
4060
|
+
filePath: chunk.filePath,
|
|
4061
|
+
startOffset: match.startOffset,
|
|
4062
|
+
endOffset: match.endOffset,
|
|
4063
|
+
snippet: buildSnippet(chunk.content, match.startOffset, match.endOffset, contextChars),
|
|
4064
|
+
...chunk.pageNumbers && chunk.pageNumbers.length > 0 ? { pageNumbers: [...chunk.pageNumbers] } : {}
|
|
4065
|
+
};
|
|
4066
|
+
}
|
|
4086
4067
|
function matchesGrepScope(chunk, params) {
|
|
4087
4068
|
if (params.chunkType && chunk.chunkType !== params.chunkType) {
|
|
4088
4069
|
return false;
|
package/dist/index.mjs
CHANGED
|
@@ -2549,17 +2549,7 @@ var Knowledge = class _Knowledge {
|
|
|
2549
2549
|
scannedChunks += 1;
|
|
2550
2550
|
const chunkMatches = matcher(chunk.content);
|
|
2551
2551
|
for (const match of chunkMatches) {
|
|
2552
|
-
matches.push(
|
|
2553
|
-
position: chunk.position,
|
|
2554
|
-
chunkId: chunk.chunkId,
|
|
2555
|
-
chunkType: chunk.chunkType,
|
|
2556
|
-
sectionPath: chunk.sectionPath,
|
|
2557
|
-
sourceChunkPath: chunk.sourceChunkPath,
|
|
2558
|
-
filePath: chunk.filePath,
|
|
2559
|
-
startOffset: match.startOffset,
|
|
2560
|
-
endOffset: match.endOffset,
|
|
2561
|
-
snippet: buildSnippet(chunk.content, match.startOffset, match.endOffset, contextChars)
|
|
2562
|
-
});
|
|
2552
|
+
matches.push(toGrepMatch(chunk, match, contextChars));
|
|
2563
2553
|
if (matches.length >= maxResults) {
|
|
2564
2554
|
return { document, matches, scannedChunks, truncated: true };
|
|
2565
2555
|
}
|
|
@@ -2573,7 +2563,8 @@ var Knowledge = class _Knowledge {
|
|
|
2573
2563
|
query: params.query,
|
|
2574
2564
|
namespace: params.namespace,
|
|
2575
2565
|
topK: params.topK,
|
|
2576
|
-
|
|
2566
|
+
// Omit when undefined so the API default (map-nav) applies; false → classic.
|
|
2567
|
+
useAgentic: params.useAgentic
|
|
2577
2568
|
});
|
|
2578
2569
|
const documentByServerId = new Map(
|
|
2579
2570
|
localDocuments.filter((document) => document.documentId).map((document) => [document.documentId, document])
|
|
@@ -2790,31 +2781,17 @@ var Knowledge = class _Knowledge {
|
|
|
2790
2781
|
if (response.pagination.page === startPage && cursor?.nextChunkIndex !== void 0 && chunkIndex < cursor.nextChunkIndex) {
|
|
2791
2782
|
continue;
|
|
2792
2783
|
}
|
|
2793
|
-
|
|
2784
|
+
const indexed = toIndexedRemoteChunk(chunk);
|
|
2785
|
+
if (!matchesGrepScope(indexed, params)) {
|
|
2794
2786
|
continue;
|
|
2795
2787
|
}
|
|
2796
2788
|
scannedChunks += 1;
|
|
2797
|
-
const chunkMatches = matcher(
|
|
2789
|
+
const chunkMatches = matcher(indexed.content);
|
|
2798
2790
|
for (const [matchIndex, match] of chunkMatches.entries()) {
|
|
2799
2791
|
if (response.pagination.page === startPage && cursor?.nextChunkIndex === chunkIndex && cursor.nextMatchIndex !== void 0 && matchIndex < cursor.nextMatchIndex) {
|
|
2800
2792
|
continue;
|
|
2801
2793
|
}
|
|
2802
|
-
matches.push(
|
|
2803
|
-
position: toChunkPosition(chunk),
|
|
2804
|
-
chunkId: chunk.chunkId,
|
|
2805
|
-
chunkType: chunk.chunkType,
|
|
2806
|
-
sectionPath: chunk.sectionPath ?? "",
|
|
2807
|
-
sourceChunkPath: chunk.sourceChunkPath ?? chunk.sectionPath ?? "",
|
|
2808
|
-
filePath: chunk.filePath ?? void 0,
|
|
2809
|
-
startOffset: match.startOffset,
|
|
2810
|
-
endOffset: match.endOffset,
|
|
2811
|
-
snippet: buildSnippet(
|
|
2812
|
-
chunk.content ?? "",
|
|
2813
|
-
match.startOffset,
|
|
2814
|
-
match.endOffset,
|
|
2815
|
-
contextChars
|
|
2816
|
-
)
|
|
2817
|
-
});
|
|
2794
|
+
matches.push(toGrepMatch(indexed, match, contextChars));
|
|
2818
2795
|
if (matches.length >= maxResults) {
|
|
2819
2796
|
const continuationCursor = createGrepContinuationCursor({
|
|
2820
2797
|
documentId,
|
|
@@ -2978,17 +2955,7 @@ var Knowledge = class _Knowledge {
|
|
|
2978
2955
|
for (const chunk of scopedChunks) {
|
|
2979
2956
|
scannedChunks += 1;
|
|
2980
2957
|
for (const match of matcher(chunk.content)) {
|
|
2981
|
-
matches.push(
|
|
2982
|
-
position: chunk.position,
|
|
2983
|
-
chunkId: chunk.chunkId,
|
|
2984
|
-
chunkType: chunk.chunkType,
|
|
2985
|
-
sectionPath: chunk.sectionPath,
|
|
2986
|
-
sourceChunkPath: chunk.sourceChunkPath,
|
|
2987
|
-
filePath: chunk.filePath,
|
|
2988
|
-
startOffset: match.startOffset,
|
|
2989
|
-
endOffset: match.endOffset,
|
|
2990
|
-
snippet: buildSnippet(chunk.content, match.startOffset, match.endOffset, contextChars)
|
|
2991
|
-
});
|
|
2958
|
+
matches.push(toGrepMatch(chunk, match, contextChars));
|
|
2992
2959
|
if (matches.length >= maxResults) {
|
|
2993
2960
|
return {
|
|
2994
2961
|
document: createStoredKnowledgeDocument({
|
|
@@ -4018,6 +3985,20 @@ function toReadChunk(chunk) {
|
|
|
4018
3985
|
metadata: chunk.metadata
|
|
4019
3986
|
};
|
|
4020
3987
|
}
|
|
3988
|
+
function toGrepMatch(chunk, match, contextChars) {
|
|
3989
|
+
return {
|
|
3990
|
+
position: chunk.position,
|
|
3991
|
+
chunkId: chunk.chunkId,
|
|
3992
|
+
chunkType: chunk.chunkType,
|
|
3993
|
+
sectionPath: chunk.sectionPath,
|
|
3994
|
+
sourceChunkPath: chunk.sourceChunkPath,
|
|
3995
|
+
filePath: chunk.filePath,
|
|
3996
|
+
startOffset: match.startOffset,
|
|
3997
|
+
endOffset: match.endOffset,
|
|
3998
|
+
snippet: buildSnippet(chunk.content, match.startOffset, match.endOffset, contextChars),
|
|
3999
|
+
...chunk.pageNumbers && chunk.pageNumbers.length > 0 ? { pageNumbers: [...chunk.pageNumbers] } : {}
|
|
4000
|
+
};
|
|
4001
|
+
}
|
|
4021
4002
|
function matchesGrepScope(chunk, params) {
|
|
4022
4003
|
if (params.chunkType && chunk.chunkType !== params.chunkType) {
|
|
4023
4004
|
return false;
|