Skip to content

RAGFlow is an agent-native database: a Retrieval-Augmented Generation (RAG) engine that grew into context infrastructure.

Update api.md (#2196)

JobSmithManipulation97e4eccf0368
diff --git a/docs/references/api.md b/docs/references/api.md
index b4eb432b96..65698a4ae2 100644
--- a/docs/references/api.md
+++ b/docs/references/api.md
@@ -398,7 +398,43 @@ This method uploads a specific file to a specified knowledge base.
"retmsg": "success"
}
```
-
+### Demo for Upload File(Python)
+
+```python
+# upload_to_kb.py
+import requests
+
+
+def upload_file_to_kb(file_path, kb_name, token='ragflow-xxxxxxxxxxxxx', parser_id='naive'):
+ """
+ Uploads a file to a knowledge base.
+
+ Args:
+ - file_path: Path to the file to upload.
+ - kb_name: Name of the target knowledge base.
+ - parser_id: ID of the chosen file parser (defaults to 'naive').
+ - token: API token for authentication.
+ """
+ url = 'http://127.0.0.1/v1/api/document/upload' # Replace with your actual API URL
+ files = {'file': open(file_path, 'rb')} # The file to upload
+ data = {'kb_name': kb_name, 'parser_id': parser_id, 'run': '1'} # Additional form data
+ headers = {'Authorization': f'Bearer {token}'} # Replace with your actual Bearer token
+
+ response = requests.post(url, files=files, data=data, headers=headers)
+
+ if response.status_code == 200:
+ print("File uploaded successfully:", response.json())
+ else:
+ print("Failed to upload file:", response.status_code, response.text)
+
+file_to_upload = './ai_intro.pdf' # For example: './documents/report.pdf'
+knowledge_base_name = 'AI_knowledge_base'
+# Assume you have already obtained your token and set it here
+token = 'ragflow-xxxxxxxxxxxxx'
+
+# Call the function to upload the file
+upload_file_to_kb(file_to_upload, knowledge_base_name, token=token)
+```
## Get document chunks
This method retrieves the chunks of a specific document by `doc_name` or `doc_id`.