RAG document upload
Ingest a file into the workspace knowledge base, then pass document_id in rag_options with use_rag=True.
Supported extensions include pdf, txt, md, csv, json, docx (see RAG_UPLOAD_EXTENSIONS in the SDK). rag_ensure_document uploads and waits, or reuses a ready document with the same filename when reuse_existing=True (default).
python
from tokensaver_sdk import TokenSaver
ts = TokenSaver(api_key="ts_...")
doc = ts.rag_ensure_document("./path/to/example_document.docx")doc_id = str(doc["document_id"])
q1 = ts.ask(
"What is this document about? Answer in one short paragraph.",
provider="openai",
model="gpt-4o",
use_rag=True,
rag_similarity_threshold=0.55,
rag_options={"document_ids": [doc_id]},)
print(q1.text)
q2 = ts.ask(
"List three key points from the document.",
provider="openai",
model="gpt-4o",
use_rag=True,
use_compression=True,
compression_level=4,
rag_options={"document_ids": [doc_id], "top_k": 8},)
print(q2.text)
Lower-level upload (no wait)
python
meta = ts.rag_upload_document("./notes.md", name="notes.md")ts.rag_wait_document_ready(meta["document_id"])
# Or one call:
# ready = ts.rag_upload_and_wait("./data/report.pdf")