@ontos-ai/knowhere-sdk 2.1.3 → 2.2.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 +51 -0
- package/dist/index.d.mts +74 -3
- package/dist/index.d.ts +74 -3
- package/dist/index.js +52 -44
- package/dist/index.mjs +50 -44
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -145,6 +145,56 @@ const result = await client.parse({
|
|
|
145
145
|
});
|
|
146
146
|
```
|
|
147
147
|
|
|
148
|
+
### Bring Your Own Key (BYOK)
|
|
149
|
+
|
|
150
|
+
Pass per-request LLM credentials via `llmConfig` on parse/job create and
|
|
151
|
+
retrieval queries. Flat root applies to both channels; use `models` for
|
|
152
|
+
different model ids on the same endpoint, or `text` / `vision` for different
|
|
153
|
+
provider endpoints. Use camelCase in TypeScript; the HTTP client serializes to
|
|
154
|
+
snake_case on the wire.
|
|
155
|
+
|
|
156
|
+
```typescript
|
|
157
|
+
// Multimodal shorthand — one model for text + vision
|
|
158
|
+
const llmConfig = {
|
|
159
|
+
apiKey: process.env.OPENAI_API_KEY,
|
|
160
|
+
model: 'gpt-4o',
|
|
161
|
+
baseUrl: 'https://api.openai.com/v1',
|
|
162
|
+
};
|
|
163
|
+
|
|
164
|
+
// Same endpoint, different models per channel
|
|
165
|
+
const modelsConfig = {
|
|
166
|
+
apiKey: process.env.OPENAI_API_KEY,
|
|
167
|
+
baseUrl: 'https://api.openai.com/v1',
|
|
168
|
+
models: { text: 'gpt-4o-mini', vision: 'gpt-4o' },
|
|
169
|
+
};
|
|
170
|
+
|
|
171
|
+
// Or two different endpoints
|
|
172
|
+
const splitLlmConfig = {
|
|
173
|
+
text: {
|
|
174
|
+
apiKey: process.env.OPENAI_API_KEY,
|
|
175
|
+
model: 'gpt-4o-mini',
|
|
176
|
+
baseUrl: 'https://api.openai.com/v1',
|
|
177
|
+
},
|
|
178
|
+
vision: {
|
|
179
|
+
apiKey: process.env.DASHSCOPE_API_KEY,
|
|
180
|
+
model: 'qwen-vl-max',
|
|
181
|
+
baseUrl: 'https://dashscope.aliyuncs.com/compatible-mode/v1',
|
|
182
|
+
},
|
|
183
|
+
};
|
|
184
|
+
|
|
185
|
+
const result = await client.parse({
|
|
186
|
+
url: 'https://example.com/doc.pdf',
|
|
187
|
+
llmConfig: modelsConfig,
|
|
188
|
+
});
|
|
189
|
+
|
|
190
|
+
const response = await client.retrieval.query({
|
|
191
|
+
namespace: 'support-center',
|
|
192
|
+
query: 'What is the refund policy?',
|
|
193
|
+
useAgentic: true,
|
|
194
|
+
llmConfig: splitLlmConfig,
|
|
195
|
+
});
|
|
196
|
+
```
|
|
197
|
+
|
|
148
198
|
### Page Citation Assets
|
|
149
199
|
|
|
150
200
|
Page citation assets are generated by Knowhere during page-memory parsing. The
|
|
@@ -373,6 +423,7 @@ const grep = await client.knowledge.grepChunks({
|
|
|
373
423
|
pattern: 'warranty',
|
|
374
424
|
maxResults: 10,
|
|
375
425
|
});
|
|
426
|
+
// grep.matches include pageNumbers when the source chunk has them.
|
|
376
427
|
|
|
377
428
|
const serverSearch = await client.knowledge.search({
|
|
378
429
|
query: 'battery warranty',
|
package/dist/index.d.mts
CHANGED
|
@@ -516,6 +516,47 @@ interface WebhookConfig {
|
|
|
516
516
|
/** Webhook URL to notify on job completion */
|
|
517
517
|
url: string;
|
|
518
518
|
}
|
|
519
|
+
/**
|
|
520
|
+
* Per-provider BYOK credentials and routing overrides.
|
|
521
|
+
*/
|
|
522
|
+
interface LlmProviderConfig {
|
|
523
|
+
/** Provider API key */
|
|
524
|
+
apiKey?: string;
|
|
525
|
+
/** Model identifier */
|
|
526
|
+
model?: string;
|
|
527
|
+
/** Provider base URL override */
|
|
528
|
+
baseUrl?: string;
|
|
529
|
+
}
|
|
530
|
+
/**
|
|
531
|
+
* Per-channel model ids that share root apiKey / baseUrl.
|
|
532
|
+
*/
|
|
533
|
+
interface LlmModelsConfig {
|
|
534
|
+
/** Text / planning model id */
|
|
535
|
+
text?: string;
|
|
536
|
+
/** Vision / VLM model id */
|
|
537
|
+
vision?: string;
|
|
538
|
+
}
|
|
539
|
+
/**
|
|
540
|
+
* Bring-your-own-key LLM configuration.
|
|
541
|
+
*
|
|
542
|
+
* Flat root (`apiKey` / `model` / `baseUrl`) applies to both channels.
|
|
543
|
+
* Use `models` for different model ids on the same endpoint, or `text` /
|
|
544
|
+
* `vision` objects for different provider endpoints.
|
|
545
|
+
*/
|
|
546
|
+
interface LlmConfig {
|
|
547
|
+
/** Default provider API key (with model/models + baseUrl) */
|
|
548
|
+
apiKey?: string;
|
|
549
|
+
/** Default model for both channels (overridden by models.*) */
|
|
550
|
+
model?: string;
|
|
551
|
+
/** Default OpenAI-compatible base URL */
|
|
552
|
+
baseUrl?: string;
|
|
553
|
+
/** Per-channel model ids sharing root apiKey / baseUrl */
|
|
554
|
+
models?: LlmModelsConfig;
|
|
555
|
+
/** Text / chat credentials (replaces root for text) */
|
|
556
|
+
text?: LlmProviderConfig;
|
|
557
|
+
/** Vision / VLM credentials (replaces root for vision) */
|
|
558
|
+
vision?: LlmProviderConfig;
|
|
559
|
+
}
|
|
519
560
|
/**
|
|
520
561
|
* Client-provided display metadata copied onto the published document.
|
|
521
562
|
*/
|
|
@@ -540,6 +581,8 @@ interface CreateJobParams {
|
|
|
540
581
|
documentMetadata?: DocumentMetadata;
|
|
541
582
|
/** Parsing configuration */
|
|
542
583
|
parsingParams?: ParsingParams;
|
|
584
|
+
/** Bring-your-own-key LLM credentials for this job */
|
|
585
|
+
llmConfig?: LlmConfig;
|
|
543
586
|
/** Webhook configuration */
|
|
544
587
|
webhook?: WebhookConfig;
|
|
545
588
|
}
|
|
@@ -621,6 +664,8 @@ interface ParseParams {
|
|
|
621
664
|
* assets into application-owned storage before the result is returned.
|
|
622
665
|
*/
|
|
623
666
|
storageAdapter?: KnowhereAssetStorageOptions;
|
|
667
|
+
/** Bring-your-own-key LLM credentials for this parse */
|
|
668
|
+
llmConfig?: LlmConfig;
|
|
624
669
|
/** Webhook configuration */
|
|
625
670
|
webhook?: WebhookConfig;
|
|
626
671
|
/** Upload progress callback */
|
|
@@ -733,7 +778,10 @@ declare abstract class BaseResource {
|
|
|
733
778
|
declare class Jobs extends BaseResource {
|
|
734
779
|
private pendingUploadJobs;
|
|
735
780
|
/**
|
|
736
|
-
* Create a new parsing job
|
|
781
|
+
* Create a new parsing job.
|
|
782
|
+
*
|
|
783
|
+
* Auto-attaches `documentMetadata.createdByClient` / `clientVersion` for
|
|
784
|
+
* OSS telemetry. Caller-provided metadata keys win; defaults fill gaps only.
|
|
737
785
|
*/
|
|
738
786
|
create(params: CreateJobParams): Promise<Job>;
|
|
739
787
|
/**
|
|
@@ -815,6 +863,8 @@ interface RetrievalQueryParams {
|
|
|
815
863
|
excludeDocumentIds?: string[];
|
|
816
864
|
/** Document sections to exclude for this request only */
|
|
817
865
|
excludeSections?: RetrievalSectionExclusion[];
|
|
866
|
+
/** Bring-your-own-key LLM credentials for this query */
|
|
867
|
+
llmConfig?: LlmConfig;
|
|
818
868
|
}
|
|
819
869
|
/**
|
|
820
870
|
* Caller-facing source reference attached to a retrieval result.
|
|
@@ -1305,6 +1355,8 @@ interface KnowledgeGrepMatch {
|
|
|
1305
1355
|
startOffset: number;
|
|
1306
1356
|
endOffset: number;
|
|
1307
1357
|
snippet: string;
|
|
1358
|
+
/** Copied from the source chunk when the indexed chunk has page numbers. */
|
|
1359
|
+
pageNumbers?: number[];
|
|
1308
1360
|
}
|
|
1309
1361
|
interface KnowledgeGrepResponse {
|
|
1310
1362
|
document: LocalKnowledgeDocument;
|
|
@@ -1488,7 +1540,26 @@ declare class Knowhere {
|
|
|
1488
1540
|
startParse(params: ParseParams): Promise<Job>;
|
|
1489
1541
|
}
|
|
1490
1542
|
|
|
1491
|
-
declare const VERSION = "
|
|
1543
|
+
declare const VERSION = "2.1.3";
|
|
1544
|
+
|
|
1545
|
+
/**
|
|
1546
|
+
* Official Knowhere client identity written into job `document_metadata`.
|
|
1547
|
+
*
|
|
1548
|
+
* Wire format (snake_case on the wire after HTTP serialization):
|
|
1549
|
+
* `{ created_by_client, client_version }`.
|
|
1550
|
+
*
|
|
1551
|
+
* Merge rule used by every official client: caller-provided keys win;
|
|
1552
|
+
* defaults only fill keys that are missing.
|
|
1553
|
+
*/
|
|
1554
|
+
declare const NODE_SDK_DOCUMENT_METADATA_DEFAULTS: {
|
|
1555
|
+
readonly createdByClient: "node-sdk";
|
|
1556
|
+
readonly clientVersion: "2.1.3";
|
|
1557
|
+
};
|
|
1558
|
+
/**
|
|
1559
|
+
* Merge official-client defaults under caller-provided document metadata.
|
|
1560
|
+
* Existing keys on `provided` are preserved; defaults fill gaps only.
|
|
1561
|
+
*/
|
|
1562
|
+
declare function mergeDocumentMetadataDefaults(defaults: DocumentMetadata, provided?: DocumentMetadata | null): DocumentMetadata;
|
|
1492
1563
|
|
|
1493
1564
|
declare function storeParseResultAssets(result: ParseResult, options?: KnowhereAssetStorageOptions): Promise<KnowhereAssetStorageResult>;
|
|
1494
1565
|
|
|
@@ -1651,4 +1722,4 @@ declare class JobFailedError extends KnowhereError {
|
|
|
1651
1722
|
constructor(message: string, code: string, jobResult: JobResult);
|
|
1652
1723
|
}
|
|
1653
1724
|
|
|
1654
|
-
export { APIError, type AuthTokenProvider, AuthenticationError, BadRequestError, type BaseChunk, ChecksumError, type Chunk, ConflictError, type CreateJobParams, DiskParsedDocumentStorage, type DocType, type Document, type DocumentChunk, type DocumentChunkGetParams, type DocumentChunkListParams, type DocumentChunkListResponse, type DocumentChunkPagination, type DocumentChunkResponse, type DocumentChunkType, type DocumentListPagination, type DocumentListParams, type DocumentListResponse, type DocumentMetadata, type DocumentPageCitationSource, Documents, type FileIndex, GatewayTimeoutError, type ImageChunk, InternalServerError, InvalidStateError, type Job, type JobError, JobFailedError, type JobResult, type JobStatus, Jobs, Knowhere, type KnowhereAssetStorageAdapter, type KnowhereAssetStorageBody, type KnowhereAssetStorageHead, type KnowhereAssetStorageObject, type KnowhereAssetStorageOptions, type KnowhereAssetStorageResult, type KnowhereAssetStorageWriteResult, KnowhereError, type KnowhereOptions, Knowledge, type KnowledgeAsyncJobStatusResponse, type KnowledgeAsyncParseParams, type KnowledgeAsyncParseResponse, type KnowledgeCacheDocumentParams, type KnowledgeCacheJobResultParams, type KnowledgeChunkType, type KnowledgeDocumentReference, type KnowledgeGrepMatch, type KnowledgeGrepParams, type KnowledgeGrepResponse, type KnowledgeImportJobResultParams, type KnowledgeJobResultResponse, type KnowledgeLoadJobResultParams, type KnowledgeOutline, type KnowledgeParseParams, type KnowledgeParsedStorageOptions, type KnowledgeReadChunk, type KnowledgeReadParams, type KnowledgeReadResponse, type KnowledgeSearchParams, type KnowledgeSearchReference, type KnowledgeSearchResponse, type KnowledgeSearchResult, type KnowledgeSection, type KnowledgeStartupRecoveryResponse, type KnowledgeSyncParsedDocumentParams, type KnowledgeSyncParsedDocumentResponse, type LoadOptions, type LocalKnowledgeDocument, type LocalKnowledgeParseResponse, LocalKnowledgeStore, type Manifest, NetworkError, NotFoundError, type PageChunk, type PageCitationAsset, type PageCitationAssetContentType, type PageCitationAssetSource, type ParseParams, type ParseResult, type ParsedDocumentCommit, type ParsedDocumentCommitSource, type ParsedDocumentObject, type ParsedDocumentObjectHead, type ParsedDocumentObjectParams, type ParsedDocumentRevisionParams, type ParsedDocumentStorage, type ParsedDocumentStorageConfig, type ParsedDocumentStorageDocument, type ParsedDocumentStorageLimits, type ParsedDocumentSyncProgress, type ParsedDocumentSyncScheduler, type ParsedDocumentWriteObjectParams, type ParsedDocumentWriteObjectResult, type ParsingModel, type ParsingParams, PaymentRequiredError, PermissionDeniedError, type PollProgress, PollingTimeoutError, RateLimitError, Retrieval, type RetrievalChannel, type RetrievalChunkType, type RetrievalFilterMode, type RetrievalQueryParams, type RetrievalQueryResponse, type RetrievalReferencedChunk, type RetrievalResult, type RetrievalSectionExclusion, type RetrievalSource, ServiceUnavailableError, type Statistics, type TableChunk, type TextChunk, TimeoutError, type UploadParams, type UploadProgress, VERSION, ValidationError, type WaitOptions, type WebhookConfig, Knowhere as default, storeParseResultAssets, syncParseResultToParsedDocumentStorage };
|
|
1725
|
+
export { APIError, type AuthTokenProvider, AuthenticationError, BadRequestError, type BaseChunk, ChecksumError, type Chunk, ConflictError, type CreateJobParams, DiskParsedDocumentStorage, type DocType, type Document, type DocumentChunk, type DocumentChunkGetParams, type DocumentChunkListParams, type DocumentChunkListResponse, type DocumentChunkPagination, type DocumentChunkResponse, type DocumentChunkType, type DocumentListPagination, type DocumentListParams, type DocumentListResponse, type DocumentMetadata, type DocumentPageCitationSource, Documents, type FileIndex, GatewayTimeoutError, type ImageChunk, InternalServerError, InvalidStateError, type Job, type JobError, JobFailedError, type JobResult, type JobStatus, Jobs, Knowhere, type KnowhereAssetStorageAdapter, type KnowhereAssetStorageBody, type KnowhereAssetStorageHead, type KnowhereAssetStorageObject, type KnowhereAssetStorageOptions, type KnowhereAssetStorageResult, type KnowhereAssetStorageWriteResult, KnowhereError, type KnowhereOptions, Knowledge, type KnowledgeAsyncJobStatusResponse, type KnowledgeAsyncParseParams, type KnowledgeAsyncParseResponse, type KnowledgeCacheDocumentParams, type KnowledgeCacheJobResultParams, type KnowledgeChunkType, type KnowledgeDocumentReference, type KnowledgeGrepMatch, type KnowledgeGrepParams, type KnowledgeGrepResponse, type KnowledgeImportJobResultParams, type KnowledgeJobResultResponse, type KnowledgeLoadJobResultParams, type KnowledgeOutline, type KnowledgeParseParams, type KnowledgeParsedStorageOptions, type KnowledgeReadChunk, type KnowledgeReadParams, type KnowledgeReadResponse, type KnowledgeSearchParams, type KnowledgeSearchReference, type KnowledgeSearchResponse, type KnowledgeSearchResult, type KnowledgeSection, type KnowledgeStartupRecoveryResponse, type KnowledgeSyncParsedDocumentParams, type KnowledgeSyncParsedDocumentResponse, type LlmConfig, type LlmModelsConfig, type LlmProviderConfig, type LoadOptions, type LocalKnowledgeDocument, type LocalKnowledgeParseResponse, LocalKnowledgeStore, type Manifest, NODE_SDK_DOCUMENT_METADATA_DEFAULTS, NetworkError, NotFoundError, type PageChunk, type PageCitationAsset, type PageCitationAssetContentType, type PageCitationAssetSource, type ParseParams, type ParseResult, type ParsedDocumentCommit, type ParsedDocumentCommitSource, type ParsedDocumentObject, type ParsedDocumentObjectHead, type ParsedDocumentObjectParams, type ParsedDocumentRevisionParams, type ParsedDocumentStorage, type ParsedDocumentStorageConfig, type ParsedDocumentStorageDocument, type ParsedDocumentStorageLimits, type ParsedDocumentSyncProgress, type ParsedDocumentSyncScheduler, type ParsedDocumentWriteObjectParams, type ParsedDocumentWriteObjectResult, type ParsingModel, type ParsingParams, PaymentRequiredError, PermissionDeniedError, type PollProgress, PollingTimeoutError, RateLimitError, Retrieval, type RetrievalChannel, type RetrievalChunkType, type RetrievalFilterMode, type RetrievalQueryParams, type RetrievalQueryResponse, type RetrievalReferencedChunk, type RetrievalResult, type RetrievalSectionExclusion, type RetrievalSource, ServiceUnavailableError, type Statistics, type TableChunk, type TextChunk, TimeoutError, type UploadParams, type UploadProgress, VERSION, ValidationError, type WaitOptions, type WebhookConfig, Knowhere as default, mergeDocumentMetadataDefaults, storeParseResultAssets, syncParseResultToParsedDocumentStorage };
|
package/dist/index.d.ts
CHANGED
|
@@ -516,6 +516,47 @@ interface WebhookConfig {
|
|
|
516
516
|
/** Webhook URL to notify on job completion */
|
|
517
517
|
url: string;
|
|
518
518
|
}
|
|
519
|
+
/**
|
|
520
|
+
* Per-provider BYOK credentials and routing overrides.
|
|
521
|
+
*/
|
|
522
|
+
interface LlmProviderConfig {
|
|
523
|
+
/** Provider API key */
|
|
524
|
+
apiKey?: string;
|
|
525
|
+
/** Model identifier */
|
|
526
|
+
model?: string;
|
|
527
|
+
/** Provider base URL override */
|
|
528
|
+
baseUrl?: string;
|
|
529
|
+
}
|
|
530
|
+
/**
|
|
531
|
+
* Per-channel model ids that share root apiKey / baseUrl.
|
|
532
|
+
*/
|
|
533
|
+
interface LlmModelsConfig {
|
|
534
|
+
/** Text / planning model id */
|
|
535
|
+
text?: string;
|
|
536
|
+
/** Vision / VLM model id */
|
|
537
|
+
vision?: string;
|
|
538
|
+
}
|
|
539
|
+
/**
|
|
540
|
+
* Bring-your-own-key LLM configuration.
|
|
541
|
+
*
|
|
542
|
+
* Flat root (`apiKey` / `model` / `baseUrl`) applies to both channels.
|
|
543
|
+
* Use `models` for different model ids on the same endpoint, or `text` /
|
|
544
|
+
* `vision` objects for different provider endpoints.
|
|
545
|
+
*/
|
|
546
|
+
interface LlmConfig {
|
|
547
|
+
/** Default provider API key (with model/models + baseUrl) */
|
|
548
|
+
apiKey?: string;
|
|
549
|
+
/** Default model for both channels (overridden by models.*) */
|
|
550
|
+
model?: string;
|
|
551
|
+
/** Default OpenAI-compatible base URL */
|
|
552
|
+
baseUrl?: string;
|
|
553
|
+
/** Per-channel model ids sharing root apiKey / baseUrl */
|
|
554
|
+
models?: LlmModelsConfig;
|
|
555
|
+
/** Text / chat credentials (replaces root for text) */
|
|
556
|
+
text?: LlmProviderConfig;
|
|
557
|
+
/** Vision / VLM credentials (replaces root for vision) */
|
|
558
|
+
vision?: LlmProviderConfig;
|
|
559
|
+
}
|
|
519
560
|
/**
|
|
520
561
|
* Client-provided display metadata copied onto the published document.
|
|
521
562
|
*/
|
|
@@ -540,6 +581,8 @@ interface CreateJobParams {
|
|
|
540
581
|
documentMetadata?: DocumentMetadata;
|
|
541
582
|
/** Parsing configuration */
|
|
542
583
|
parsingParams?: ParsingParams;
|
|
584
|
+
/** Bring-your-own-key LLM credentials for this job */
|
|
585
|
+
llmConfig?: LlmConfig;
|
|
543
586
|
/** Webhook configuration */
|
|
544
587
|
webhook?: WebhookConfig;
|
|
545
588
|
}
|
|
@@ -621,6 +664,8 @@ interface ParseParams {
|
|
|
621
664
|
* assets into application-owned storage before the result is returned.
|
|
622
665
|
*/
|
|
623
666
|
storageAdapter?: KnowhereAssetStorageOptions;
|
|
667
|
+
/** Bring-your-own-key LLM credentials for this parse */
|
|
668
|
+
llmConfig?: LlmConfig;
|
|
624
669
|
/** Webhook configuration */
|
|
625
670
|
webhook?: WebhookConfig;
|
|
626
671
|
/** Upload progress callback */
|
|
@@ -733,7 +778,10 @@ declare abstract class BaseResource {
|
|
|
733
778
|
declare class Jobs extends BaseResource {
|
|
734
779
|
private pendingUploadJobs;
|
|
735
780
|
/**
|
|
736
|
-
* Create a new parsing job
|
|
781
|
+
* Create a new parsing job.
|
|
782
|
+
*
|
|
783
|
+
* Auto-attaches `documentMetadata.createdByClient` / `clientVersion` for
|
|
784
|
+
* OSS telemetry. Caller-provided metadata keys win; defaults fill gaps only.
|
|
737
785
|
*/
|
|
738
786
|
create(params: CreateJobParams): Promise<Job>;
|
|
739
787
|
/**
|
|
@@ -815,6 +863,8 @@ interface RetrievalQueryParams {
|
|
|
815
863
|
excludeDocumentIds?: string[];
|
|
816
864
|
/** Document sections to exclude for this request only */
|
|
817
865
|
excludeSections?: RetrievalSectionExclusion[];
|
|
866
|
+
/** Bring-your-own-key LLM credentials for this query */
|
|
867
|
+
llmConfig?: LlmConfig;
|
|
818
868
|
}
|
|
819
869
|
/**
|
|
820
870
|
* Caller-facing source reference attached to a retrieval result.
|
|
@@ -1305,6 +1355,8 @@ interface KnowledgeGrepMatch {
|
|
|
1305
1355
|
startOffset: number;
|
|
1306
1356
|
endOffset: number;
|
|
1307
1357
|
snippet: string;
|
|
1358
|
+
/** Copied from the source chunk when the indexed chunk has page numbers. */
|
|
1359
|
+
pageNumbers?: number[];
|
|
1308
1360
|
}
|
|
1309
1361
|
interface KnowledgeGrepResponse {
|
|
1310
1362
|
document: LocalKnowledgeDocument;
|
|
@@ -1488,7 +1540,26 @@ declare class Knowhere {
|
|
|
1488
1540
|
startParse(params: ParseParams): Promise<Job>;
|
|
1489
1541
|
}
|
|
1490
1542
|
|
|
1491
|
-
declare const VERSION = "
|
|
1543
|
+
declare const VERSION = "2.1.3";
|
|
1544
|
+
|
|
1545
|
+
/**
|
|
1546
|
+
* Official Knowhere client identity written into job `document_metadata`.
|
|
1547
|
+
*
|
|
1548
|
+
* Wire format (snake_case on the wire after HTTP serialization):
|
|
1549
|
+
* `{ created_by_client, client_version }`.
|
|
1550
|
+
*
|
|
1551
|
+
* Merge rule used by every official client: caller-provided keys win;
|
|
1552
|
+
* defaults only fill keys that are missing.
|
|
1553
|
+
*/
|
|
1554
|
+
declare const NODE_SDK_DOCUMENT_METADATA_DEFAULTS: {
|
|
1555
|
+
readonly createdByClient: "node-sdk";
|
|
1556
|
+
readonly clientVersion: "2.1.3";
|
|
1557
|
+
};
|
|
1558
|
+
/**
|
|
1559
|
+
* Merge official-client defaults under caller-provided document metadata.
|
|
1560
|
+
* Existing keys on `provided` are preserved; defaults fill gaps only.
|
|
1561
|
+
*/
|
|
1562
|
+
declare function mergeDocumentMetadataDefaults(defaults: DocumentMetadata, provided?: DocumentMetadata | null): DocumentMetadata;
|
|
1492
1563
|
|
|
1493
1564
|
declare function storeParseResultAssets(result: ParseResult, options?: KnowhereAssetStorageOptions): Promise<KnowhereAssetStorageResult>;
|
|
1494
1565
|
|
|
@@ -1651,4 +1722,4 @@ declare class JobFailedError extends KnowhereError {
|
|
|
1651
1722
|
constructor(message: string, code: string, jobResult: JobResult);
|
|
1652
1723
|
}
|
|
1653
1724
|
|
|
1654
|
-
export { APIError, type AuthTokenProvider, AuthenticationError, BadRequestError, type BaseChunk, ChecksumError, type Chunk, ConflictError, type CreateJobParams, DiskParsedDocumentStorage, type DocType, type Document, type DocumentChunk, type DocumentChunkGetParams, type DocumentChunkListParams, type DocumentChunkListResponse, type DocumentChunkPagination, type DocumentChunkResponse, type DocumentChunkType, type DocumentListPagination, type DocumentListParams, type DocumentListResponse, type DocumentMetadata, type DocumentPageCitationSource, Documents, type FileIndex, GatewayTimeoutError, type ImageChunk, InternalServerError, InvalidStateError, type Job, type JobError, JobFailedError, type JobResult, type JobStatus, Jobs, Knowhere, type KnowhereAssetStorageAdapter, type KnowhereAssetStorageBody, type KnowhereAssetStorageHead, type KnowhereAssetStorageObject, type KnowhereAssetStorageOptions, type KnowhereAssetStorageResult, type KnowhereAssetStorageWriteResult, KnowhereError, type KnowhereOptions, Knowledge, type KnowledgeAsyncJobStatusResponse, type KnowledgeAsyncParseParams, type KnowledgeAsyncParseResponse, type KnowledgeCacheDocumentParams, type KnowledgeCacheJobResultParams, type KnowledgeChunkType, type KnowledgeDocumentReference, type KnowledgeGrepMatch, type KnowledgeGrepParams, type KnowledgeGrepResponse, type KnowledgeImportJobResultParams, type KnowledgeJobResultResponse, type KnowledgeLoadJobResultParams, type KnowledgeOutline, type KnowledgeParseParams, type KnowledgeParsedStorageOptions, type KnowledgeReadChunk, type KnowledgeReadParams, type KnowledgeReadResponse, type KnowledgeSearchParams, type KnowledgeSearchReference, type KnowledgeSearchResponse, type KnowledgeSearchResult, type KnowledgeSection, type KnowledgeStartupRecoveryResponse, type KnowledgeSyncParsedDocumentParams, type KnowledgeSyncParsedDocumentResponse, type LoadOptions, type LocalKnowledgeDocument, type LocalKnowledgeParseResponse, LocalKnowledgeStore, type Manifest, NetworkError, NotFoundError, type PageChunk, type PageCitationAsset, type PageCitationAssetContentType, type PageCitationAssetSource, type ParseParams, type ParseResult, type ParsedDocumentCommit, type ParsedDocumentCommitSource, type ParsedDocumentObject, type ParsedDocumentObjectHead, type ParsedDocumentObjectParams, type ParsedDocumentRevisionParams, type ParsedDocumentStorage, type ParsedDocumentStorageConfig, type ParsedDocumentStorageDocument, type ParsedDocumentStorageLimits, type ParsedDocumentSyncProgress, type ParsedDocumentSyncScheduler, type ParsedDocumentWriteObjectParams, type ParsedDocumentWriteObjectResult, type ParsingModel, type ParsingParams, PaymentRequiredError, PermissionDeniedError, type PollProgress, PollingTimeoutError, RateLimitError, Retrieval, type RetrievalChannel, type RetrievalChunkType, type RetrievalFilterMode, type RetrievalQueryParams, type RetrievalQueryResponse, type RetrievalReferencedChunk, type RetrievalResult, type RetrievalSectionExclusion, type RetrievalSource, ServiceUnavailableError, type Statistics, type TableChunk, type TextChunk, TimeoutError, type UploadParams, type UploadProgress, VERSION, ValidationError, type WaitOptions, type WebhookConfig, Knowhere as default, storeParseResultAssets, syncParseResultToParsedDocumentStorage };
|
|
1725
|
+
export { APIError, type AuthTokenProvider, AuthenticationError, BadRequestError, type BaseChunk, ChecksumError, type Chunk, ConflictError, type CreateJobParams, DiskParsedDocumentStorage, type DocType, type Document, type DocumentChunk, type DocumentChunkGetParams, type DocumentChunkListParams, type DocumentChunkListResponse, type DocumentChunkPagination, type DocumentChunkResponse, type DocumentChunkType, type DocumentListPagination, type DocumentListParams, type DocumentListResponse, type DocumentMetadata, type DocumentPageCitationSource, Documents, type FileIndex, GatewayTimeoutError, type ImageChunk, InternalServerError, InvalidStateError, type Job, type JobError, JobFailedError, type JobResult, type JobStatus, Jobs, Knowhere, type KnowhereAssetStorageAdapter, type KnowhereAssetStorageBody, type KnowhereAssetStorageHead, type KnowhereAssetStorageObject, type KnowhereAssetStorageOptions, type KnowhereAssetStorageResult, type KnowhereAssetStorageWriteResult, KnowhereError, type KnowhereOptions, Knowledge, type KnowledgeAsyncJobStatusResponse, type KnowledgeAsyncParseParams, type KnowledgeAsyncParseResponse, type KnowledgeCacheDocumentParams, type KnowledgeCacheJobResultParams, type KnowledgeChunkType, type KnowledgeDocumentReference, type KnowledgeGrepMatch, type KnowledgeGrepParams, type KnowledgeGrepResponse, type KnowledgeImportJobResultParams, type KnowledgeJobResultResponse, type KnowledgeLoadJobResultParams, type KnowledgeOutline, type KnowledgeParseParams, type KnowledgeParsedStorageOptions, type KnowledgeReadChunk, type KnowledgeReadParams, type KnowledgeReadResponse, type KnowledgeSearchParams, type KnowledgeSearchReference, type KnowledgeSearchResponse, type KnowledgeSearchResult, type KnowledgeSection, type KnowledgeStartupRecoveryResponse, type KnowledgeSyncParsedDocumentParams, type KnowledgeSyncParsedDocumentResponse, type LlmConfig, type LlmModelsConfig, type LlmProviderConfig, type LoadOptions, type LocalKnowledgeDocument, type LocalKnowledgeParseResponse, LocalKnowledgeStore, type Manifest, NODE_SDK_DOCUMENT_METADATA_DEFAULTS, NetworkError, NotFoundError, type PageChunk, type PageCitationAsset, type PageCitationAssetContentType, type PageCitationAssetSource, type ParseParams, type ParseResult, type ParsedDocumentCommit, type ParsedDocumentCommitSource, type ParsedDocumentObject, type ParsedDocumentObjectHead, type ParsedDocumentObjectParams, type ParsedDocumentRevisionParams, type ParsedDocumentStorage, type ParsedDocumentStorageConfig, type ParsedDocumentStorageDocument, type ParsedDocumentStorageLimits, type ParsedDocumentSyncProgress, type ParsedDocumentSyncScheduler, type ParsedDocumentWriteObjectParams, type ParsedDocumentWriteObjectResult, type ParsingModel, type ParsingParams, PaymentRequiredError, PermissionDeniedError, type PollProgress, PollingTimeoutError, RateLimitError, Retrieval, type RetrievalChannel, type RetrievalChunkType, type RetrievalFilterMode, type RetrievalQueryParams, type RetrievalQueryResponse, type RetrievalReferencedChunk, type RetrievalResult, type RetrievalSectionExclusion, type RetrievalSource, ServiceUnavailableError, type Statistics, type TableChunk, type TextChunk, TimeoutError, type UploadParams, type UploadProgress, VERSION, ValidationError, type WaitOptions, type WebhookConfig, Knowhere as default, mergeDocumentMetadataDefaults, storeParseResultAssets, syncParseResultToParsedDocumentStorage };
|
package/dist/index.js
CHANGED
|
@@ -46,6 +46,7 @@ __export(index_exports, {
|
|
|
46
46
|
KnowhereError: () => KnowhereError,
|
|
47
47
|
Knowledge: () => Knowledge,
|
|
48
48
|
LocalKnowledgeStore: () => LocalKnowledgeStore,
|
|
49
|
+
NODE_SDK_DOCUMENT_METADATA_DEFAULTS: () => NODE_SDK_DOCUMENT_METADATA_DEFAULTS,
|
|
49
50
|
NetworkError: () => NetworkError,
|
|
50
51
|
NotFoundError: () => NotFoundError,
|
|
51
52
|
PaymentRequiredError: () => PaymentRequiredError,
|
|
@@ -58,6 +59,7 @@ __export(index_exports, {
|
|
|
58
59
|
VERSION: () => VERSION,
|
|
59
60
|
ValidationError: () => ValidationError,
|
|
60
61
|
default: () => Knowhere,
|
|
62
|
+
mergeDocumentMetadataDefaults: () => mergeDocumentMetadataDefaults,
|
|
61
63
|
storeParseResultAssets: () => storeParseResultAssets,
|
|
62
64
|
syncParseResultToParsedDocumentStorage: () => syncParseResultToParsedDocumentStorage
|
|
63
65
|
});
|
|
@@ -70,7 +72,7 @@ var import_path3 = __toESM(require("path"));
|
|
|
70
72
|
var import_axios = __toESM(require("axios"));
|
|
71
73
|
|
|
72
74
|
// src/version.ts
|
|
73
|
-
var VERSION = "
|
|
75
|
+
var VERSION = "2.1.3";
|
|
74
76
|
|
|
75
77
|
// src/constants.ts
|
|
76
78
|
var DEFAULT_BASE_URL = "https://api.knowhereto.ai";
|
|
@@ -764,6 +766,18 @@ var BaseResource = class {
|
|
|
764
766
|
}
|
|
765
767
|
};
|
|
766
768
|
|
|
769
|
+
// src/lib/document-metadata.ts
|
|
770
|
+
var NODE_SDK_DOCUMENT_METADATA_DEFAULTS = {
|
|
771
|
+
createdByClient: "node-sdk",
|
|
772
|
+
clientVersion: VERSION
|
|
773
|
+
};
|
|
774
|
+
function mergeDocumentMetadataDefaults(defaults, provided) {
|
|
775
|
+
if (!provided) {
|
|
776
|
+
return { ...defaults };
|
|
777
|
+
}
|
|
778
|
+
return { ...defaults, ...provided };
|
|
779
|
+
}
|
|
780
|
+
|
|
767
781
|
// src/lib/upload.ts
|
|
768
782
|
var import_fs = require("fs");
|
|
769
783
|
async function uploadFile(httpClient, uploadUrl, file, options) {
|
|
@@ -1356,10 +1370,20 @@ function isMissingFileError(error) {
|
|
|
1356
1370
|
var Jobs = class extends BaseResource {
|
|
1357
1371
|
pendingUploadJobs = /* @__PURE__ */ new Map();
|
|
1358
1372
|
/**
|
|
1359
|
-
* Create a new parsing job
|
|
1373
|
+
* Create a new parsing job.
|
|
1374
|
+
*
|
|
1375
|
+
* Auto-attaches `documentMetadata.createdByClient` / `clientVersion` for
|
|
1376
|
+
* OSS telemetry. Caller-provided metadata keys win; defaults fill gaps only.
|
|
1360
1377
|
*/
|
|
1361
1378
|
async create(params) {
|
|
1362
|
-
const
|
|
1379
|
+
const documentMetadata = mergeDocumentMetadataDefaults(
|
|
1380
|
+
NODE_SDK_DOCUMENT_METADATA_DEFAULTS,
|
|
1381
|
+
params.documentMetadata
|
|
1382
|
+
);
|
|
1383
|
+
const job = await this.httpClient.post(this.endpoint("/jobs"), {
|
|
1384
|
+
...params,
|
|
1385
|
+
documentMetadata
|
|
1386
|
+
});
|
|
1363
1387
|
if (job.uploadUrl) {
|
|
1364
1388
|
this.pendingUploadJobs.set(job.jobId, job);
|
|
1365
1389
|
}
|
|
@@ -2590,17 +2614,7 @@ var Knowledge = class _Knowledge {
|
|
|
2590
2614
|
scannedChunks += 1;
|
|
2591
2615
|
const chunkMatches = matcher(chunk.content);
|
|
2592
2616
|
for (const match of chunkMatches) {
|
|
2593
|
-
matches.push(
|
|
2594
|
-
position: chunk.position,
|
|
2595
|
-
chunkId: chunk.chunkId,
|
|
2596
|
-
chunkType: chunk.chunkType,
|
|
2597
|
-
sectionPath: chunk.sectionPath,
|
|
2598
|
-
sourceChunkPath: chunk.sourceChunkPath,
|
|
2599
|
-
filePath: chunk.filePath,
|
|
2600
|
-
startOffset: match.startOffset,
|
|
2601
|
-
endOffset: match.endOffset,
|
|
2602
|
-
snippet: buildSnippet(chunk.content, match.startOffset, match.endOffset, contextChars)
|
|
2603
|
-
});
|
|
2617
|
+
matches.push(toGrepMatch(chunk, match, contextChars));
|
|
2604
2618
|
if (matches.length >= maxResults) {
|
|
2605
2619
|
return { document, matches, scannedChunks, truncated: true };
|
|
2606
2620
|
}
|
|
@@ -2614,7 +2628,8 @@ var Knowledge = class _Knowledge {
|
|
|
2614
2628
|
query: params.query,
|
|
2615
2629
|
namespace: params.namespace,
|
|
2616
2630
|
topK: params.topK,
|
|
2617
|
-
|
|
2631
|
+
// Omit when undefined so the API default (map-nav) applies; false → classic.
|
|
2632
|
+
useAgentic: params.useAgentic
|
|
2618
2633
|
});
|
|
2619
2634
|
const documentByServerId = new Map(
|
|
2620
2635
|
localDocuments.filter((document) => document.documentId).map((document) => [document.documentId, document])
|
|
@@ -2831,31 +2846,17 @@ var Knowledge = class _Knowledge {
|
|
|
2831
2846
|
if (response.pagination.page === startPage && cursor?.nextChunkIndex !== void 0 && chunkIndex < cursor.nextChunkIndex) {
|
|
2832
2847
|
continue;
|
|
2833
2848
|
}
|
|
2834
|
-
|
|
2849
|
+
const indexed = toIndexedRemoteChunk(chunk);
|
|
2850
|
+
if (!matchesGrepScope(indexed, params)) {
|
|
2835
2851
|
continue;
|
|
2836
2852
|
}
|
|
2837
2853
|
scannedChunks += 1;
|
|
2838
|
-
const chunkMatches = matcher(
|
|
2854
|
+
const chunkMatches = matcher(indexed.content);
|
|
2839
2855
|
for (const [matchIndex, match] of chunkMatches.entries()) {
|
|
2840
2856
|
if (response.pagination.page === startPage && cursor?.nextChunkIndex === chunkIndex && cursor.nextMatchIndex !== void 0 && matchIndex < cursor.nextMatchIndex) {
|
|
2841
2857
|
continue;
|
|
2842
2858
|
}
|
|
2843
|
-
matches.push(
|
|
2844
|
-
position: toChunkPosition(chunk),
|
|
2845
|
-
chunkId: chunk.chunkId,
|
|
2846
|
-
chunkType: chunk.chunkType,
|
|
2847
|
-
sectionPath: chunk.sectionPath ?? "",
|
|
2848
|
-
sourceChunkPath: chunk.sourceChunkPath ?? chunk.sectionPath ?? "",
|
|
2849
|
-
filePath: chunk.filePath ?? void 0,
|
|
2850
|
-
startOffset: match.startOffset,
|
|
2851
|
-
endOffset: match.endOffset,
|
|
2852
|
-
snippet: buildSnippet(
|
|
2853
|
-
chunk.content ?? "",
|
|
2854
|
-
match.startOffset,
|
|
2855
|
-
match.endOffset,
|
|
2856
|
-
contextChars
|
|
2857
|
-
)
|
|
2858
|
-
});
|
|
2859
|
+
matches.push(toGrepMatch(indexed, match, contextChars));
|
|
2859
2860
|
if (matches.length >= maxResults) {
|
|
2860
2861
|
const continuationCursor = createGrepContinuationCursor({
|
|
2861
2862
|
documentId,
|
|
@@ -3019,17 +3020,7 @@ var Knowledge = class _Knowledge {
|
|
|
3019
3020
|
for (const chunk of scopedChunks) {
|
|
3020
3021
|
scannedChunks += 1;
|
|
3021
3022
|
for (const match of matcher(chunk.content)) {
|
|
3022
|
-
matches.push(
|
|
3023
|
-
position: chunk.position,
|
|
3024
|
-
chunkId: chunk.chunkId,
|
|
3025
|
-
chunkType: chunk.chunkType,
|
|
3026
|
-
sectionPath: chunk.sectionPath,
|
|
3027
|
-
sourceChunkPath: chunk.sourceChunkPath,
|
|
3028
|
-
filePath: chunk.filePath,
|
|
3029
|
-
startOffset: match.startOffset,
|
|
3030
|
-
endOffset: match.endOffset,
|
|
3031
|
-
snippet: buildSnippet(chunk.content, match.startOffset, match.endOffset, contextChars)
|
|
3032
|
-
});
|
|
3023
|
+
matches.push(toGrepMatch(chunk, match, contextChars));
|
|
3033
3024
|
if (matches.length >= maxResults) {
|
|
3034
3025
|
return {
|
|
3035
3026
|
document: createStoredKnowledgeDocument({
|
|
@@ -4059,6 +4050,20 @@ function toReadChunk(chunk) {
|
|
|
4059
4050
|
metadata: chunk.metadata
|
|
4060
4051
|
};
|
|
4061
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
|
+
}
|
|
4062
4067
|
function matchesGrepScope(chunk, params) {
|
|
4063
4068
|
if (params.chunkType && chunk.chunkType !== params.chunkType) {
|
|
4064
4069
|
return false;
|
|
@@ -4267,6 +4272,7 @@ var Knowhere = class {
|
|
|
4267
4272
|
documentId: params.documentId,
|
|
4268
4273
|
documentMetadata: params.documentMetadata,
|
|
4269
4274
|
parsingParams: buildParsingParams(params),
|
|
4275
|
+
llmConfig: params.llmConfig,
|
|
4270
4276
|
webhook
|
|
4271
4277
|
});
|
|
4272
4278
|
if (params.file) {
|
|
@@ -4451,6 +4457,7 @@ function isMissingFileError3(error) {
|
|
|
4451
4457
|
KnowhereError,
|
|
4452
4458
|
Knowledge,
|
|
4453
4459
|
LocalKnowledgeStore,
|
|
4460
|
+
NODE_SDK_DOCUMENT_METADATA_DEFAULTS,
|
|
4454
4461
|
NetworkError,
|
|
4455
4462
|
NotFoundError,
|
|
4456
4463
|
PaymentRequiredError,
|
|
@@ -4462,6 +4469,7 @@ function isMissingFileError3(error) {
|
|
|
4462
4469
|
TimeoutError,
|
|
4463
4470
|
VERSION,
|
|
4464
4471
|
ValidationError,
|
|
4472
|
+
mergeDocumentMetadataDefaults,
|
|
4465
4473
|
storeParseResultAssets,
|
|
4466
4474
|
syncParseResultToParsedDocumentStorage
|
|
4467
4475
|
});
|
package/dist/index.mjs
CHANGED
|
@@ -7,7 +7,7 @@ import axios, {
|
|
|
7
7
|
} from "axios";
|
|
8
8
|
|
|
9
9
|
// src/version.ts
|
|
10
|
-
var VERSION = "
|
|
10
|
+
var VERSION = "2.1.3";
|
|
11
11
|
|
|
12
12
|
// src/constants.ts
|
|
13
13
|
var DEFAULT_BASE_URL = "https://api.knowhereto.ai";
|
|
@@ -701,6 +701,18 @@ var BaseResource = class {
|
|
|
701
701
|
}
|
|
702
702
|
};
|
|
703
703
|
|
|
704
|
+
// src/lib/document-metadata.ts
|
|
705
|
+
var NODE_SDK_DOCUMENT_METADATA_DEFAULTS = {
|
|
706
|
+
createdByClient: "node-sdk",
|
|
707
|
+
clientVersion: VERSION
|
|
708
|
+
};
|
|
709
|
+
function mergeDocumentMetadataDefaults(defaults, provided) {
|
|
710
|
+
if (!provided) {
|
|
711
|
+
return { ...defaults };
|
|
712
|
+
}
|
|
713
|
+
return { ...defaults, ...provided };
|
|
714
|
+
}
|
|
715
|
+
|
|
704
716
|
// src/lib/upload.ts
|
|
705
717
|
import { createReadStream, promises as fs } from "fs";
|
|
706
718
|
async function uploadFile(httpClient, uploadUrl, file, options) {
|
|
@@ -1293,10 +1305,20 @@ function isMissingFileError(error) {
|
|
|
1293
1305
|
var Jobs = class extends BaseResource {
|
|
1294
1306
|
pendingUploadJobs = /* @__PURE__ */ new Map();
|
|
1295
1307
|
/**
|
|
1296
|
-
* Create a new parsing job
|
|
1308
|
+
* Create a new parsing job.
|
|
1309
|
+
*
|
|
1310
|
+
* Auto-attaches `documentMetadata.createdByClient` / `clientVersion` for
|
|
1311
|
+
* OSS telemetry. Caller-provided metadata keys win; defaults fill gaps only.
|
|
1297
1312
|
*/
|
|
1298
1313
|
async create(params) {
|
|
1299
|
-
const
|
|
1314
|
+
const documentMetadata = mergeDocumentMetadataDefaults(
|
|
1315
|
+
NODE_SDK_DOCUMENT_METADATA_DEFAULTS,
|
|
1316
|
+
params.documentMetadata
|
|
1317
|
+
);
|
|
1318
|
+
const job = await this.httpClient.post(this.endpoint("/jobs"), {
|
|
1319
|
+
...params,
|
|
1320
|
+
documentMetadata
|
|
1321
|
+
});
|
|
1300
1322
|
if (job.uploadUrl) {
|
|
1301
1323
|
this.pendingUploadJobs.set(job.jobId, job);
|
|
1302
1324
|
}
|
|
@@ -2527,17 +2549,7 @@ var Knowledge = class _Knowledge {
|
|
|
2527
2549
|
scannedChunks += 1;
|
|
2528
2550
|
const chunkMatches = matcher(chunk.content);
|
|
2529
2551
|
for (const match of chunkMatches) {
|
|
2530
|
-
matches.push(
|
|
2531
|
-
position: chunk.position,
|
|
2532
|
-
chunkId: chunk.chunkId,
|
|
2533
|
-
chunkType: chunk.chunkType,
|
|
2534
|
-
sectionPath: chunk.sectionPath,
|
|
2535
|
-
sourceChunkPath: chunk.sourceChunkPath,
|
|
2536
|
-
filePath: chunk.filePath,
|
|
2537
|
-
startOffset: match.startOffset,
|
|
2538
|
-
endOffset: match.endOffset,
|
|
2539
|
-
snippet: buildSnippet(chunk.content, match.startOffset, match.endOffset, contextChars)
|
|
2540
|
-
});
|
|
2552
|
+
matches.push(toGrepMatch(chunk, match, contextChars));
|
|
2541
2553
|
if (matches.length >= maxResults) {
|
|
2542
2554
|
return { document, matches, scannedChunks, truncated: true };
|
|
2543
2555
|
}
|
|
@@ -2551,7 +2563,8 @@ var Knowledge = class _Knowledge {
|
|
|
2551
2563
|
query: params.query,
|
|
2552
2564
|
namespace: params.namespace,
|
|
2553
2565
|
topK: params.topK,
|
|
2554
|
-
|
|
2566
|
+
// Omit when undefined so the API default (map-nav) applies; false → classic.
|
|
2567
|
+
useAgentic: params.useAgentic
|
|
2555
2568
|
});
|
|
2556
2569
|
const documentByServerId = new Map(
|
|
2557
2570
|
localDocuments.filter((document) => document.documentId).map((document) => [document.documentId, document])
|
|
@@ -2768,31 +2781,17 @@ var Knowledge = class _Knowledge {
|
|
|
2768
2781
|
if (response.pagination.page === startPage && cursor?.nextChunkIndex !== void 0 && chunkIndex < cursor.nextChunkIndex) {
|
|
2769
2782
|
continue;
|
|
2770
2783
|
}
|
|
2771
|
-
|
|
2784
|
+
const indexed = toIndexedRemoteChunk(chunk);
|
|
2785
|
+
if (!matchesGrepScope(indexed, params)) {
|
|
2772
2786
|
continue;
|
|
2773
2787
|
}
|
|
2774
2788
|
scannedChunks += 1;
|
|
2775
|
-
const chunkMatches = matcher(
|
|
2789
|
+
const chunkMatches = matcher(indexed.content);
|
|
2776
2790
|
for (const [matchIndex, match] of chunkMatches.entries()) {
|
|
2777
2791
|
if (response.pagination.page === startPage && cursor?.nextChunkIndex === chunkIndex && cursor.nextMatchIndex !== void 0 && matchIndex < cursor.nextMatchIndex) {
|
|
2778
2792
|
continue;
|
|
2779
2793
|
}
|
|
2780
|
-
matches.push(
|
|
2781
|
-
position: toChunkPosition(chunk),
|
|
2782
|
-
chunkId: chunk.chunkId,
|
|
2783
|
-
chunkType: chunk.chunkType,
|
|
2784
|
-
sectionPath: chunk.sectionPath ?? "",
|
|
2785
|
-
sourceChunkPath: chunk.sourceChunkPath ?? chunk.sectionPath ?? "",
|
|
2786
|
-
filePath: chunk.filePath ?? void 0,
|
|
2787
|
-
startOffset: match.startOffset,
|
|
2788
|
-
endOffset: match.endOffset,
|
|
2789
|
-
snippet: buildSnippet(
|
|
2790
|
-
chunk.content ?? "",
|
|
2791
|
-
match.startOffset,
|
|
2792
|
-
match.endOffset,
|
|
2793
|
-
contextChars
|
|
2794
|
-
)
|
|
2795
|
-
});
|
|
2794
|
+
matches.push(toGrepMatch(indexed, match, contextChars));
|
|
2796
2795
|
if (matches.length >= maxResults) {
|
|
2797
2796
|
const continuationCursor = createGrepContinuationCursor({
|
|
2798
2797
|
documentId,
|
|
@@ -2956,17 +2955,7 @@ var Knowledge = class _Knowledge {
|
|
|
2956
2955
|
for (const chunk of scopedChunks) {
|
|
2957
2956
|
scannedChunks += 1;
|
|
2958
2957
|
for (const match of matcher(chunk.content)) {
|
|
2959
|
-
matches.push(
|
|
2960
|
-
position: chunk.position,
|
|
2961
|
-
chunkId: chunk.chunkId,
|
|
2962
|
-
chunkType: chunk.chunkType,
|
|
2963
|
-
sectionPath: chunk.sectionPath,
|
|
2964
|
-
sourceChunkPath: chunk.sourceChunkPath,
|
|
2965
|
-
filePath: chunk.filePath,
|
|
2966
|
-
startOffset: match.startOffset,
|
|
2967
|
-
endOffset: match.endOffset,
|
|
2968
|
-
snippet: buildSnippet(chunk.content, match.startOffset, match.endOffset, contextChars)
|
|
2969
|
-
});
|
|
2958
|
+
matches.push(toGrepMatch(chunk, match, contextChars));
|
|
2970
2959
|
if (matches.length >= maxResults) {
|
|
2971
2960
|
return {
|
|
2972
2961
|
document: createStoredKnowledgeDocument({
|
|
@@ -3996,6 +3985,20 @@ function toReadChunk(chunk) {
|
|
|
3996
3985
|
metadata: chunk.metadata
|
|
3997
3986
|
};
|
|
3998
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
|
+
}
|
|
3999
4002
|
function matchesGrepScope(chunk, params) {
|
|
4000
4003
|
if (params.chunkType && chunk.chunkType !== params.chunkType) {
|
|
4001
4004
|
return false;
|
|
@@ -4204,6 +4207,7 @@ var Knowhere = class {
|
|
|
4204
4207
|
documentId: params.documentId,
|
|
4205
4208
|
documentMetadata: params.documentMetadata,
|
|
4206
4209
|
parsingParams: buildParsingParams(params),
|
|
4210
|
+
llmConfig: params.llmConfig,
|
|
4207
4211
|
webhook
|
|
4208
4212
|
});
|
|
4209
4213
|
if (params.file) {
|
|
@@ -4387,6 +4391,7 @@ export {
|
|
|
4387
4391
|
KnowhereError,
|
|
4388
4392
|
Knowledge,
|
|
4389
4393
|
LocalKnowledgeStore,
|
|
4394
|
+
NODE_SDK_DOCUMENT_METADATA_DEFAULTS,
|
|
4390
4395
|
NetworkError,
|
|
4391
4396
|
NotFoundError,
|
|
4392
4397
|
PaymentRequiredError,
|
|
@@ -4399,6 +4404,7 @@ export {
|
|
|
4399
4404
|
VERSION,
|
|
4400
4405
|
ValidationError,
|
|
4401
4406
|
Knowhere as default,
|
|
4407
|
+
mergeDocumentMetadataDefaults,
|
|
4402
4408
|
storeParseResultAssets,
|
|
4403
4409
|
syncParseResultToParsedDocumentStorage
|
|
4404
4410
|
};
|