-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbasic.ts
More file actions
44 lines (37 loc) Β· 1.25 KB
/
basic.ts
File metadata and controls
44 lines (37 loc) Β· 1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
/**
* Basic usage example - Parse document from URL
*/
import Knowhere from '@ontos-ai/knowhere-sdk';
async function main() {
// Initialize client with API key
const client = new Knowhere({
apiKey: process.env.KNOWHERE_API_KEY,
});
try {
// Parse document from URL
console.log('Starting document parsing...');
const result = await client.parse({
url: 'https://example.com/sample.pdf',
});
// Print statistics
console.log('\nπ Parsing complete!');
console.log(`ββ Text chunks: ${result.textChunks.length}`);
console.log(`ββ Image chunks: ${result.imageChunks.length}`);
console.log(`ββ Table chunks: ${result.tableChunks.length}`);
console.log(`ββ Job ID: ${result.jobId}`);
// Print first text chunk
if (result.textChunks.length > 0) {
const firstChunk = result.textChunks[0];
console.log('\nπ First text chunk:');
console.log(`Content: ${firstChunk.content.substring(0, 100)}...`);
console.log(`Keywords: ${firstChunk.keywords?.join(', ')}`);
}
// Save results to disk
await result.save('./output');
console.log('\nπΎ Results saved to ./output');
} catch (error) {
console.error('β Error:', error);
process.exit(1);
}
}
main();