curl -X POST https://api.example.com/api/knowledge/documents/stream \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-H "Accept: text/event-stream" \
-N \
-d '{
"projectId": "proj_123",
"fileName": "large-document.pdf",
"fileType": "pdf",
"sourceType": "upload",
"content": "Large document content..."
}'
const response = await fetch('https://api.example.com/api/knowledge/documents/stream', {
method: 'POST',
headers: {
'Authorization': 'Bearer YOUR_API_KEY',
'Content-Type': 'application/json',
'Accept': 'text/event-stream'
},
body: JSON.stringify({
projectId: 'proj_123',
fileName: 'large-document.pdf',
fileType: 'pdf',
sourceType: 'upload',
content: 'Large document content...'
})
});
const reader = response.body.getReader();
const decoder = new TextDecoder();
while (true) {
const { done, value } = await reader.read();
if (done) break;
const chunk = decoder.decode(value);
const lines = chunk.split('\n');
for (const line of lines) {
if (line.startsWith('data: ')) {
const event = JSON.parse(line.slice(6));
console.log('Progress:', event.progress, event.message);
}
}
}
import requests
import json
response = requests.post(
'https://api.example.com/api/knowledge/documents/stream',
headers={
'Authorization': 'Bearer YOUR_API_KEY',
'Content-Type': 'application/json',
'Accept': 'text/event-stream'
},
json={
'projectId': 'proj_123',
'fileName': 'large-document.pdf',
'fileType': 'pdf',
'sourceType': 'upload',
'content': 'Large document content...'
},
stream=True
)
for line in response.iter_lines():
if line:
decoded = line.decode('utf-8')
if decoded.startswith('data: '):
event = json.loads(decoded[6:])
print(f"Progress: {event['progress']}% - {event['message']}")
data: {"type":"progress","progress":10,"message":"Parsing document"}
data: {"type":"progress","progress":30,"message":"Extracting text"}
data: {"type":"progress","progress":60,"message":"Creating embeddings"}
data: {"type":"progress","progress":90,"message":"Storing vectors"}
data: {"type":"complete","progress":100,"message":"Document indexed successfully","documentId":"doc_abc123xyz"}
Documents
Create and Index Document (Streaming)
Creates and indexes a document with real-time progress updates via Server-Sent Events
POST
/
api
/
knowledge
/
documents
/
stream
curl -X POST https://api.example.com/api/knowledge/documents/stream \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-H "Accept: text/event-stream" \
-N \
-d '{
"projectId": "proj_123",
"fileName": "large-document.pdf",
"fileType": "pdf",
"sourceType": "upload",
"content": "Large document content..."
}'
const response = await fetch('https://api.example.com/api/knowledge/documents/stream', {
method: 'POST',
headers: {
'Authorization': 'Bearer YOUR_API_KEY',
'Content-Type': 'application/json',
'Accept': 'text/event-stream'
},
body: JSON.stringify({
projectId: 'proj_123',
fileName: 'large-document.pdf',
fileType: 'pdf',
sourceType: 'upload',
content: 'Large document content...'
})
});
const reader = response.body.getReader();
const decoder = new TextDecoder();
while (true) {
const { done, value } = await reader.read();
if (done) break;
const chunk = decoder.decode(value);
const lines = chunk.split('\n');
for (const line of lines) {
if (line.startsWith('data: ')) {
const event = JSON.parse(line.slice(6));
console.log('Progress:', event.progress, event.message);
}
}
}
import requests
import json
response = requests.post(
'https://api.example.com/api/knowledge/documents/stream',
headers={
'Authorization': 'Bearer YOUR_API_KEY',
'Content-Type': 'application/json',
'Accept': 'text/event-stream'
},
json={
'projectId': 'proj_123',
'fileName': 'large-document.pdf',
'fileType': 'pdf',
'sourceType': 'upload',
'content': 'Large document content...'
},
stream=True
)
for line in response.iter_lines():
if line:
decoded = line.decode('utf-8')
if decoded.startswith('data: '):
event = json.loads(decoded[6:])
print(f"Progress: {event['progress']}% - {event['message']}")
data: {"type":"progress","progress":10,"message":"Parsing document"}
data: {"type":"progress","progress":30,"message":"Extracting text"}
data: {"type":"progress","progress":60,"message":"Creating embeddings"}
data: {"type":"progress","progress":90,"message":"Storing vectors"}
data: {"type":"complete","progress":100,"message":"Document indexed successfully","documentId":"doc_abc123xyz"}
Request Body
string
required
Project ID to associate the document with
string
required
Name of the file/document
string
required
Type of file (e.g.,
pdf, txt, md, docx)string
required
Source type of the document (e.g.,
upload, url, integration)string
required
Content of the document to be indexed
string
Optional file ID if document is linked to a file
Response
This endpoint returns a Server-Sent Events (SSE) stream with real-time progress updates.string
Event type (e.g.,
progress, complete, error)number
Progress percentage (0-100)
string
Current status message
curl -X POST https://api.example.com/api/knowledge/documents/stream \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-H "Accept: text/event-stream" \
-N \
-d '{
"projectId": "proj_123",
"fileName": "large-document.pdf",
"fileType": "pdf",
"sourceType": "upload",
"content": "Large document content..."
}'
const response = await fetch('https://api.example.com/api/knowledge/documents/stream', {
method: 'POST',
headers: {
'Authorization': 'Bearer YOUR_API_KEY',
'Content-Type': 'application/json',
'Accept': 'text/event-stream'
},
body: JSON.stringify({
projectId: 'proj_123',
fileName: 'large-document.pdf',
fileType: 'pdf',
sourceType: 'upload',
content: 'Large document content...'
})
});
const reader = response.body.getReader();
const decoder = new TextDecoder();
while (true) {
const { done, value } = await reader.read();
if (done) break;
const chunk = decoder.decode(value);
const lines = chunk.split('\n');
for (const line of lines) {
if (line.startsWith('data: ')) {
const event = JSON.parse(line.slice(6));
console.log('Progress:', event.progress, event.message);
}
}
}
import requests
import json
response = requests.post(
'https://api.example.com/api/knowledge/documents/stream',
headers={
'Authorization': 'Bearer YOUR_API_KEY',
'Content-Type': 'application/json',
'Accept': 'text/event-stream'
},
json={
'projectId': 'proj_123',
'fileName': 'large-document.pdf',
'fileType': 'pdf',
'sourceType': 'upload',
'content': 'Large document content...'
},
stream=True
)
for line in response.iter_lines():
if line:
decoded = line.decode('utf-8')
if decoded.startswith('data: '):
event = json.loads(decoded[6:])
print(f"Progress: {event['progress']}% - {event['message']}")
data: {"type":"progress","progress":10,"message":"Parsing document"}
data: {"type":"progress","progress":30,"message":"Extracting text"}
data: {"type":"progress","progress":60,"message":"Creating embeddings"}
data: {"type":"progress","progress":90,"message":"Storing vectors"}
data: {"type":"complete","progress":100,"message":"Document indexed successfully","documentId":"doc_abc123xyz"}
⌘I

