This repository was archived by the owner on Aug 18, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtest-graphrag.js
More file actions
executable file
·94 lines (76 loc) · 2.25 KB
/
Copy pathtest-graphrag.js
File metadata and controls
executable file
·94 lines (76 loc) · 2.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#!/usr/bin/env node
/**
* Standalone test for GraphRAG streaming
* Tests the question "What is a cat?" using GraphRAG streaming mode
*/
import { createTrustGraphSocket } from './dist/index.esm.js';
// Configuration
const USER = 'trustgraph';
const SOCKET_URL = 'ws://localhost:8088/api/v1/socket';
const QUESTION = 'What is a cat?';
console.log('GraphRAG Streaming Test');
console.log('======================');
console.log(`User: ${USER}`);
console.log(`Socket URL: ${SOCKET_URL}`);
console.log(`Question: "${QUESTION}"\n`);
// Create socket connection
const socket = createTrustGraphSocket(USER, undefined, SOCKET_URL);
// Wait for connection to establish
setTimeout(() => {
console.log('Starting GraphRAG query...\n');
let accumulated = '';
let chunkCount = 0;
// GraphRAG options
const options = {
entityLimit: 50,
tripleLimit: 30,
maxSubgraphSize: 1000,
pathLength: 2,
};
// Streaming receiver callback
const onChunk = (chunk, complete, metadata) => {
chunkCount++;
accumulated += chunk;
if (chunk) {
process.stdout.write(chunk);
}
if (complete) {
console.log('\n\n--- Streaming Complete ---');
console.log(`Total chunks received: ${chunkCount}`);
console.log(`Total characters: ${accumulated.length}`);
if (metadata) {
console.log('\nMetadata:');
if (metadata.model) console.log(` Model: ${metadata.model}`);
if (metadata.in_token) console.log(` Input tokens: ${metadata.in_token}`);
if (metadata.out_token) console.log(` Output tokens: ${metadata.out_token}`);
}
console.log('\n--- Full Response ---');
console.log(accumulated);
// Close socket and exit
socket.close();
process.exit(0);
}
};
// Error callback
const onError = (error) => {
console.error('\n\nERROR:', error);
socket.close();
process.exit(1);
};
// Execute GraphRAG streaming query
socket
.flow('default')
.graphRagStreaming(
QUESTION,
onChunk,
onError,
options,
'default' // collection
);
}, 1000); // Wait 1 second for connection
// Handle process termination
process.on('SIGINT', () => {
console.log('\n\nInterrupted. Closing socket...');
socket.close();
process.exit(0);
});