Build a RAG Agent with Mycelis Knowledge Bases
Mycelis knowledge bases handle vector storage and retrieval for you — no Pinecone, Weaviate, or pgvector setup needed. Upload documents, attach the knowledge base to an agent, and the agent automatically retrieves relevant context when answering questions.
What you'll build
An agent that answers questions about your uploaded documents, with retrieved context injected automatically into each request.
Step 1 — Create a knowledge base
- In your workspace, navigate to Knowledge Bases in the sidebar
- Click New Knowledge Base
- Give it a name (e.g.
product-docs) and optionally a description - Leave the embedding model on the default (Mycelis picks the best available in your region)
- Click Create
Step 2 — Upload documents
Click your new knowledge base to open it, then click Upload. Supported formats:
- Markdown (
.md) - Plain text (
.txt) - DOCX
You can upload multiple files at once. Mycelis chunks the documents, generates embeddings, and stores them automatically. Large PDFs take a minute or two — a green checkmark appears when indexing is complete.
For programmatic uploads, use the REST API:
curl -X POST "https://mycelis.ai/api/v1/knowledge-bases/{kb-id}/documents" \ -H "Authorization: Bearer your-pat" \ -F "file=@./your-document.pdf"
Step 3 — Attach the knowledge base to an agent
- Open the Agents section in your workspace
- Create a new agent or open an existing one
- Under Knowledge Bases, click Attach and select
product-docs - Set the retrieval strategy — "Semantic Search" works for most use cases; "Hybrid" combines keyword + semantic for better coverage of product names and codes
- Set Max retrieved chunks — start with
5, increase if answers seem incomplete - Save the agent
Step 4 — Query via the API
The agent now behaves like any other OpenAI-compatible endpoint, but it injects retrieved context before calling the model:
from openai import OpenAI
client = OpenAI(
base_url="https://mycelis.ai/api/proxy/v1",
api_key="your-mycelis-pat",
)
response = client.chat.completions.create(
model="product-docs-agent", # your agent slug
messages=[
{
"role": "user",
"content": "What are the system requirements for version 3.2?"
}
],
)
print(response.choices[0].message.content)
The agent retrieves the most relevant document chunks and includes them as context before sending the prompt to the model. Your application code is identical to any other OpenAI call.
Step 5 — Tune retrieval quality
If answers are missing information or citing wrong sections:
- Increase chunk count: raise Max retrieved chunks from 5 to 8–10
- Adjust chunk size: in knowledge base settings, set a smaller chunk size for more granular retrieval or larger for more context per chunk
- Switch to Hybrid retrieval: helps with exact product names, version numbers, and codes
- Add a system prompt: in the agent settings, add a system prompt like
"You are a product support assistant. Answer only based on the provided documents. If the answer is not in the documents, say so."to reduce hallucinations
Streaming
Works out of the box:
stream = client.chat.completions.create(
model="product-docs-agent",
messages=[{"role": "user", "content": "Summarize the installation steps."}],
stream=True,
)
for chunk in stream:
print(chunk.choices[0].delta.content or "", end="")
Keeping documents up to date
Delete and re-upload documents when they change — or use the REST API to automate this as part of your CI/CD pipeline. The knowledge base re-indexes updated files automatically.