Outcome: Ground your AI answers in your own documents. Users can ask questions in the workspace chat and get answers backed by your internal knowledge — not just the model’s training data.

Prerequisites

  • ManyLayers running with a workspace license
  • An embedding model provider configured (e.g., text-embedding-3-small via your OpenAI provider)
  • A chat model configured (e.g., gpt-4o)

Steps

1

Create a knowledge base

A knowledge base stores your documents as vector embeddings for semantic search. Give it a name and select the embedding model to use.From the workspace UI: go to Knowledge Bases → New knowledge base, choose a name and embedding model.Via API:
curl -X POST http://localhost:8180/v1/kb \
  -H "Authorization: Bearer $YOUR_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "company-docs",
    "embedding_model": "text-embedding-3-small"
  }'
Save the returned kb_id.
2

Upload your documents

Upload files directly, or connect a data source. ManyLayers chunks documents automatically and generates embeddings in the background.
# Upload a file
curl -X POST http://localhost:8180/v1/kb/$KB_ID/documents \
  -H "Authorization: Bearer $YOUR_KEY" \
  -F "file=@company-handbook.pdf"
You can also connect live data sources (Confluence, Notion, Google Drive, SharePoint) so the knowledge base stays updated automatically. See Connectors for setup.Check indexing progress:
curl http://localhost:8180/admin/indexing/status \
  -H "Authorization: Bearer $ADMIN_KEY"
3

Test the search

Before connecting to an agent, verify that search is returning relevant results:
curl -X POST http://localhost:8180/v1/kb/$KB_ID/search \
  -H "Authorization: Bearer $YOUR_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "query": "What is our parental leave policy?",
    "top_k": 5
  }'
If results are poor, check that documents have finished indexing and consider adjusting the chunk size in the knowledge base settings.
4

Create a workspace agent with the knowledge base

In the workspace UI, go to Agents → New agent. Select your chat model, attach your knowledge base, and configure the system prompt to instruct the agent to ground its answers in the retrieved documents.Example system prompt:
You are a helpful assistant for [Company]. Answer questions using only 
the information from the provided documents. If the answer isn't in the 
documents, say so — don't make up information.
Enable the knowledge base as a tool for this agent.
5

Query via chat

Open the workspace chat, select your agent, and ask questions about your documents:
User: What is our parental leave policy?
Agent: According to the company handbook, employees are entitled to...
       [Source: company-handbook.pdf, page 12]
The agent automatically retrieves relevant document chunks, passes them as context to the chat model, and cites its sources.You can also query programmatically using the standard chat completions API with the agent ID:
curl -X POST http://localhost:8180/v1/chat/completions \
  -H "Authorization: Bearer $YOUR_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-4o",
    "messages": [{"role": "user", "content": "What is our parental leave policy?"}],
    "agent_id": "your-agent-id"
  }'

Improving search quality

If answers aren’t grounded well in your documents, try these adjustments:
  • Enable reranking — add a reranker model to the knowledge base settings to improve result relevance
  • Adjust chunk size — smaller chunks (256-512 tokens) work better for specific factual lookups; larger chunks (1024+) work better for summaries
  • Add more documents — the more complete your knowledge base, the better coverage you get
  • Use web search as a fallback — enable web search alongside the knowledge base so the agent can answer questions not covered by your documents

Next steps

  • Connect live data sources with Connectors
  • Set up Evals to measure answer quality over time
  • Run canary routing to test different models for your RAG pipeline