searchDocumentsStream()
searchDocumentsStream(
request:SearchRequest):AsyncGenerator<SearchChunk>
Defined in: packages/core/src/document-search/index.ts:450
Search documents with streaming results for large result sets
Streams search results in chunks using NDJSON format. Ideal for:
- Large exports (thousands of documents)
- Real-time progress tracking
- Memory-efficient bulk operations
Parameters
| Parameter | Type | Description |
|---|---|---|
request | SearchRequest | Search request parameters (same as searchDocuments) |
Returns
AsyncGenerator<SearchChunk>
Yields
SearchChunk objects containing:
results- Array of search results in this chunkdone- Boolean indicating if this is the final chunk
Throws
401 - Not authenticated
Throws
422 - Validation error
Example
import { searchDocumentsStream } from "@cpod/sdk";
let totalProcessed = 0;
for await (const chunk of searchDocumentsStream({
query: "annual report",
sources: ["financial"],
})) {
console.log(`Received ${chunk.results.length} results`);
totalProcessed += chunk.results.length;
// Process each result
for (const doc of chunk.results) {
await processDocument(doc);
}
if (chunk.done) {
console.log(`Finished! Total: ${totalProcessed}`);
break;
}
}