Knowledge

Quickstart

Upload files, create a knowledge base and search with the official openai Python SDK.

Run Python on a server and put your develop API Key in PRAXIS_API_KEY. This example connects to develop, creates one knowledge base and two text files, and deletes them when finished.

python -m pip install openai

Save as quickstart.py and run python quickstart.py. Upload the policy file, create the store and wait for ingestion. upload_and_poll combines upload, attachment and polling for the second file. A successful upload still requires checking ingestion status.

import os
from openai import OpenAI

client = OpenAI(
    api_key=os.environ["PRAXIS_API_KEY"],
    base_url="https://api.deepraxis.com/openai/v1",
    timeout=120.0,
)
store = None
file_ids = []
try:
    uploaded = client.files.create(
        file=("refund-policy.txt", b"Refunds are available within 30 days of purchase."),
        purpose="assistants",
    )
    file_ids.append(uploaded.id)
    print("uploaded:", uploaded.id)

    store = client.vector_stores.create(
        name="Knowledge quickstart",
        file_ids=[uploaded.id],
    )
    print("store:", store.id)
    first = client.vector_stores.files.poll(
        uploaded.id, vector_store_id=store.id, poll_interval_ms=1000,
    )
    if first.status != "completed":
        raise RuntimeError(f"Ingestion failed: {first.last_error}")

    attached = client.vector_stores.files.upload_and_poll(
        vector_store_id=store.id,
        file=("refund-timing.txt", b"Refunds are processed in 5 business days."),
        poll_interval_ms=1000,
    )
    file_ids.append(attached.id)
    print("ingestion:", attached.status)
    if attached.status != "completed":
        raise RuntimeError(f"Ingestion failed: {attached.last_error}")

    results = client.vector_stores.search(
        vector_store_id=store.id,
        query="How many business days does a refund take?",
        max_num_results=5,
    )
    assert results.data, "Expected at least one matching chunk"
    for result in results.data:
        print(result.filename, result.score)
        for part in result.content:
            print(part.text)
    print("pagination:", results.has_more, results.next_page)
finally:
    try:
        if store is not None:
            deleted = client.vector_stores.delete(store.id)
            print("store deleted:", deleted.deleted)
    finally:
        for file_id in file_ids:
            deleted = client.files.delete(file_id)
            print("file deleted:", file_id, deleted.deleted)
        client.close()

Output includes file IDs, the store ID, ingestion: completed, matching text and cleanup results. Each file appears once, with its matching chunks ordered by relevance. Search does not paginate; when nothing was cut off it prints pagination: False None.

In develop measurements on 2026-10-11, text, Markdown, PDF, DOCX, CSV, JSON and HTML took roughly 4–21 seconds; one PNG took about 87 seconds. These are sample timings, not latency guarantees. Processing has a 30-minute deadline; inspect last_error if it fails.

Deleting a knowledge base retains it for 7 days for restoration. Source files are deleted separately. If you need these documents later, move cleanup after their final use in your own program.

Request fields → · Understand search results →

Export

On this page

No Headings