Knowledge Base (RAG)
The Knowledge Base API is the developer surface of Pulse Cortex, the knowledge engine. It lets you ground an agent's answers in your own documents instead of relying on whatever the model already knows. Ingest text, a file, or a URL; link it to one or more agents; and opt in to retrieval on any chat call — Cortex finds the most relevant passages and injects them, with a citation on each, before the agent answers.
This is retrieval-augmented generation done as a compiler: nothing is fine-tuned, no model weights change. Each chat call retrieves fresh, relevant chunks at request time, so updating a source updates every future answer immediately.
How it works
Embeddings run through the same provider abstraction used across PulseLABS — OpenAI's text-embedding-3-small when an OpenAI key is configured, or Ollama's nomic-embed-text for fully local setups. Both produce 768-dimensional vectors, so retrieval works identically regardless of which provider is active.
- Compile — any format (PDF, DOCX, XLSX, PPTX, CSV, HTML, or a URL) is normalized to markdown and chunked along its real heading structure; every chunk keeps its section path and an LLM one-liner situating it in the document.
- Embed — each chunk is embedded once at ingestion and stored alongside a full-text index, so both semantic and keyword search are always available.
- Retrieve — at chat time the query runs hybrid full-text + vector search, fused with Reciprocal Rank Fusion and reranked, returning the top-K passages with source, section, and similarity.
- Inject — the matches are added to the agent's context as numbered citations
[1]..[K]; the agent cites them inline, or says the knowledge base doesn't cover the question instead of guessing.
status: "processing" and flips to ready once chunking and embedding finish. Poll the source or subscribe to the source.ingested webhook. Beyond retrieval, Cortex also extracts facts, flags cross-source contradictions, and scores knowledge-base health — see Pulse Cortex.Ingesting a Knowledge Source
Send raw text — a doc page, a support FAQ, a pricing sheet, transcript, whatever your agent should know. PulseLABS chunks and embeds it server-side; there's no separate upload-then-process step.
Linking Sources to Agents
A source only feeds an agent's answers once it's linked. Link it at ingestion time via agentIds, or link/unlink afterwards with these endpoints.
Retrieving During Chat
Retrieval is opt-in per call — pass knowledge.enabled: true on a normal Agent Chat request. PulseLABS embeds the user's message, finds the top-K matching chunks across the agent's linked sources, and injects them as high-priority context before generating the response.
Request fields:
"knowledge": {
"enabled": true, // default false
"topK": 5 // chunks to retrieve, 1–20, default 5
}The response includes a knowledgeUsed array so you can cite or surface which passages informed the answer:
"knowledgeUsed": [
{
"sourceId": "kns_xxx",
"sourceName": "Pricing FAQ",
"chunkPreview": "Annual plans get a 20% discount. Refunds are issued within 14 days...",
"similarity": 0.91
}
]similarity is a cosine similarity score between 0 and 1. If your agent keeps citing irrelevant chunks, the source content is probably too coarse — split large documents into more focused sources rather than one giant blob.