Getting Started
Quickstart
Index one document, ask one question, read the stream. Working code in Python and JavaScript, no SDK to install: the API is plain HTTP.
Indexing is asynchronous: the upload call returns as soon as the file is accepted, before the passages are searchable. A question asked too early retrieves from whatever was indexed before: that is the one ordering mistake worth avoiding.
Prerequisites
An account, and an API key with the documents:write and chat:write scopes. Create one here:
Pick a name, tick the two scopes, set an expiry. The plaintext key is displayed once: copy it at that moment, the server only stores a SHA-256 hash afterwards.
1. Store the key
Put it in a .env file at the root of your project, and add that file to .gitignore before the first commit.
1# .env2QUERYMIND_API_KEY=ak_votre_cle_ici3QUERYMIND_PROJECT_ID=v0m6-4hag-6ubz-o57g-7l00The snippets below read it through python-dotenv (Python) and dotenv (Node). Nothing else is needed.
2. Index a document
Extraction, chunking and embedding happen server-side. The call returns a document id and a job id you can follow.
1curl -X POST "https://api.querymindx.tech/api/upload?project=$QUERYMIND_PROJECT_ID" \2 -H "Authorization: Bearer $QUERYMIND_API_KEY" \3 -F "file=@handbook.pdf"POST /api/upload does not use the project bound to your key. Without ?project= it writes into the account's default project, so a key scoped to one project can upload successfully and still see an empty document list: because the listing routes do filter on the key's project. Pass the UID (or the internal prj_… id) every time. The field is also accepted in the multipart body, for clients that cannot set a query string; the query parameter wins when both are present.To index a website instead, post {"url": "https://…"} to /api/upload/website; the crawl runs as a background job.
3. Ask a question
A complete client: upload then ask, reading the SSE stream. Pick your language; the three do the same two calls.
Requires requests and python-dotenv, and pip install requests python-dotenv. Run with python querymind.py.
1# pip install requests python-dotenv2import json3import os4
5import requests6from dotenv import load_dotenv7
8load_dotenv()9
10API = "https://api.querymindx.tech"11KEY = os.environ["QUERYMIND_API_KEY"]12# UID du projet (ou son identifiant prj_...). Il porte le corpus interroge :13# deux projets du meme compte ne repondent pas sur les memes documents.14PROJECT_ID = os.environ["QUERYMIND_PROJECT_ID"]15HEADERS = {"Authorization": f"Bearer {KEY}"}16
17
18def upload(path: str) -> dict:19 """Envoie un document. L'extraction et l'embedding se font cote serveur."""20 with open(path, "rb") as f:21 r = requests.post(22 f"{API}/api/upload",23 # project est requis : sans lui le document part dans le projet24 # par defaut du compte, pas dans celui de la cle.25 params={"project": PROJECT_ID},26 headers=HEADERS,27 files={"file": (os.path.basename(path), f)},28 timeout=120,29 )30 r.raise_for_status()31 return r.json()32
33
34def ask(question: str, session_id: str | None = None) -> tuple[str, list[str]]:35 """Pose une question et lit le flux SSE.36
37 Le corps arrive en Server-Sent Events : chaque evenement occupe une ligne38 « data: {json} », les evenements sont separes par une ligne vide. On39 utilise stream=True pour ne pas attendre la fin de la reponse.40 """41 payload = {"question": question}42 if session_id:43 payload["session_id"] = session_id44
45 answer, sources, buffer = "", [], ""46
47 with requests.post(48 f"{API}/projects/{PROJECT_ID}/chat/stream",49 headers={**HEADERS, "Content-Type": "application/json"},50 json=payload,51 stream=True,52 timeout=180,53 ) as r:54 r.raise_for_status()55 for raw in r.iter_lines(decode_unicode=True):56 if not raw:57 # Ligne vide : l'evenement en cours est termine.58 buffer = ""59 continue60 if not raw.startswith("data:"):61 continue62
63 event = json.loads(raw[5:].strip())64
65 if event["type"] == "chunk":66 print(event["content"], end="", flush=True)67 answer += event["content"]68 elif event["type"] == "done":69 sources = event.get("sources", [])70 elif event["type"] == "error":71 raise RuntimeError(event["message"])72
73 return answer, sources74
75
76if __name__ == "__main__":77 print(upload("handbook.pdf"))78 text, srcs = ask("What is the notice period for termination?")79 print("\n\nSources:", srcs)