Ingest files into a topic
Topics usually hold vectorized text chunks, but they can also contain registered files. Files can be read through search_mode="direct" or embedded into a vector collection.
Before you begin
Section titled “Before you begin”- A running Alquimia Platform runtime master.
- An API token with
editororplatform-adminrole (knowledge mutations require it). - A knowledge provider configured via
ALQUIMIA_KNOWLEDGE_PROVIDER(qdrant,redis, orin_memory).
Create a topic
Section titled “Create a topic”topic_id and file_id are stable string UUIDs generated by the registry. The vector-store provider is deployment configuration, so do not pass a per-topic connector, distanceMetric, or vectorSize.
curl -X POST "http://localhost:8080/knowledge/topics?agentspace_id=default" \ -H "Authorization: Bearer $API_TOKEN" \ -H "Content-Type: application/json" \ -d '{ "name": "product-docs", "description": "Product documentation and release notes", "is_active": true }'Creating a topic creates its vector collection up front by default (ensure_collection=True).
The response contains the generated topic_id.
Upload a file
Section titled “Upload a file”curl -X POST "http://localhost:8080/knowledge/files/upload?agentspace_id=default" \ -H "Authorization: Bearer $API_TOKEN" \ -F "file=@release-notes-v2.pdf"The response contains the file’s generated id.
Associate a file with a topic
Section titled “Associate a file with a topic”curl -X PUT "http://localhost:8080/knowledge/topics/<topic_id>/add/<file_id>" \ -H "Authorization: Bearer $API_TOKEN"Embed file contents for vector search
Section titled “Embed file contents for vector search”For rag or on_demand modes, parse and index the file contents into the topic’s vector collection. The CLI can do this in one step:
alquimia registry topics add-file product-docs release-notes-v2.pdf \ --namespace default \ --hydrate \ --severity read-only \ --tier-grants reader,editor,operator \ --approval-required--severity, --tier-grants, and --approval-required set a FileAccessPolicy layered on the topic’s policy. A file policy can only narrow access: a role outside the file’s tier grants never sees the file in search results, list_files, or read_file, even when it can query the topic.
This uploads the file, registers it, and indexes chunks into the topic’s collection. ingest_file() returns an IngestResult containing the file registration, the number of hydrated chunks, and whether an existing blob was reused. The CLI prints the chunk count and indicates when a blob was deduplicated.
alquimia registry topics rebuild re-indexes every file in the topic and shows each file’s name next to its registered_file_id.
ALQUIMIA_KNOWLEDGE_PROVIDER selects the vector-store backend.
Hybrid retrieval
Section titled “Hybrid retrieval”By default, topics use dense vector search. To combine dense similarity with sparse lexical search, create the topic with "retrieval": "hybrid":
alquimia registry topics add contracts \ --severity read-only \ --tier-grants reader,editor,operator \ --retrieval hybridOr set the retrieval field in TopicRegistration.config when calling POST /knowledge/topics:
{ "name": "contracts", "description": "Contract documents", "is_active": true, "config": { "retrieval": "hybrid" }}Provider behavior when retrieval is hybrid:
| Provider | Sparse leg |
|---|---|
| Qdrant | FastEmbedSparse("Qdrant/bm25") with server-side IDF. No per-process vocabulary fitting is required, so workers can query immediately after collection creation. |
| In-memory | Pure-Python BM25 + reciprocal rank fusion (RRF). |
| Redis | Logs a warning and falls back to dense search. |
alquimia registry topics rebuild can switch an existing topic between dense and hybrid.
Deduplication and chunk provenance
Section titled “Deduplication and chunk provenance”ingest_file computes a content_sha256 for every uploaded file. If the topic already contains an active file with the same hash, the runtime reuses the existing registered file and its hydrated chunks instead of re-chunking. The CLI reports when a blob was deduplicated.
Every chunk is stamped with provenance metadata:
| Field | Meaning |
|---|---|
content_sha256 | SHA-256 of the source file bytes |
locator | Page/section/line range inside the source document |
chunk_index | Position of the chunk in the generated sequence |
ingested_at | ISO timestamp of ingestion |
ingest_pipeline | Pipeline identifier used for extraction |
These fields are returned in retrieval results and recorded in the worklog, so answers can be traced back to the exact source file and location.
Direct file access
Section titled “Direct file access”If the agent uses search_mode: "direct", it gets list_files and read_file tools over the topic instead of vector search.
{ "knowledge_base": [ { "topic_id": "product-docs", "search_mode": "direct", "tier_ceiling": ["reader", "editor"] } ]}connectormust be omitted.- The topic’s
access_policyis still enforced by theKnowledgeAuthzPolicy. read_fileconverts PDF, Word, PowerPoint, Excel, and EPUB documents to text using the same ingestion loaders, protected by a threading lock.- File-level policies are also enforced, so results from
search,list_files, andread_fileare filtered accordingly.
Manage file-level access policies
Section titled “Manage file-level access policies”Set or clear a policy on an existing file:
alquimia registry files set-policy <file_id> \ --severity read-only \ --tier-grants reader,editor,operator \ --approval-required
alquimia registry files set-policy <file_id> --clearA file policy narrows the topic policy. Clearing it makes the topic policy apply directly.
Per-tag partitioning
Section titled “Per-tag partitioning”Topics, collections, and files are partitioned per version tag. Each tag gets its own snapshot of file registrations and vector collection, so fetching or running a versioned agentspace does not affect the workspace copy. Lifecycle helpers such as snapshot_files_for_tag, rehydrate_tag, drop_tag_collections, and purge_tag_blobs manage these per-tag copies.
Manage files
Section titled “Manage files”| Operation | Endpoint |
|---|---|
| List files | GET /knowledge/files |
| Download | GET /knowledge/files/download/{file_id} |
| Delete | DELETE /knowledge/files/delete/{file_id} |
| Remove from topic | PUT /knowledge/topics/{topic_id}/remove/{file_id} |
| Tag/untag file | PUT /knowledge/files/{file_id}/tag / untag |
Storage backends
Section titled “Storage backends”Files are stored outside the registry according to ALQUIMIA_FILE_STORAGE_PROVIDER:
| Provider | Key variables |
|---|---|
local | ALQUIMIA_FILE_STORAGE_LOCAL_DIR |
s3 | ALQUIMIA_FILE_STORAGE_S3_ENDPOINT_URL, ACCESS_KEY, SECRET_KEY, BUCKET |
See Runtime configuration for details.