Skip to content

Knowledge Engine ​

The Knowledge Engine (Retrieval-Augmented Generation / RAG) service provides end-to-end document ingestion, chunking, embedding, and semantic retrieval. It surfaces in the console as Data → Knowledge Engine.

Knowledge Engine ​

A Knowledge Engine module is the configuration unit that ties a chunking strategy, an embedding model, and a vector index together. The Knowledge Engine screen lists every module configured for the active project, with counters for modules, documents indexed, and chunk count.

Knowledge Engine list: three modules (HR Handbook, Support FAQ, Product Docs) with strategy, chunk size, document and chunk counts

When the project is empty the screen shows the onboarding CTA — clicking Create module opens a multi-step form where you choose the source datasource, pick chunking parameters (size, overlap, splitter), select an embedding model from Model Hub, point the output at a vector index (see Vector Stores), and — optionally — attach a Reranker to re-order results before they reach the LLM.

When a reranker is attached, retrieval becomes a two-stage pipeline: the vector store returns top-K candidates and the reranker scores them down to the final top-N. This is the recommended way to plug Cohere Rerank, Jina, Voyage, or any cross-encoder onto an existing Knowledge Engine module without changing the embedding model or vector store.

Architecture ​

Document → Chunk → Embed → Vector Store
                              ↓
Query   → Embed → Vector Search → (Reranker?) → Return Matches

Concepts ​

ConceptDescription
Knowledge Engine ModuleConfiguration container linking chunking strategy, embedding model, and vector index
DocumentA text or file ingested into a module
ChunkA segment of a document after splitting
Query LogAudit record of retrieval queries

Service Functions ​

FunctionDescription
createRagModule()Create module with chunk/embed config
updateRagModule()Update module settings
deleteRagModule()Delete module and associated data
getRagModule()Get by key
listRagModules()List modules for tenant
ingestDocument()Text ingestion: chunk → embed → store
ingestFile()File ingestion: convert → chunk → embed → store
queryRag()Semantic retrieval
deleteRagDocument()Delete document and its vectors
reingestDocument()Re-chunk and re-embed existing document
listRagDocuments()List documents in a module
listRagQueryLogs()Query audit log

Module Configuration ​

json
{
  "name": "Support Knowledge Base",
  "key": "support-kb",
  "embeddingModelKey": "text-embedding-ada-002",
  "vectorProviderKey": "vectors-prod",
  "vectorIndexKey": "support-index",
  "rerankerKey": "support-rerank",
  "chunkConfig": {
    "strategy": "recursive",
    "chunkSize": 1000,
    "chunkOverlap": 200
  }
}

rerankerKey is optional. When present, the matching reranker (see Reranker) runs after vector search and before the response is returned.

Text Ingestion ​

POST /api/client/v1/rag/modules/:key/ingest
Authorization: Bearer <token>
json
{
  "fileName": "product-faq.txt",
  "content": "Long document text here...",
  "contentType": "text/plain",
  "metadata": { "source": "docs", "version": "2.0" }
}

Pipeline:

  1. Split text into chunks using configured strategy
  2. Generate embeddings for each chunk
  3. Upsert vectors to the vector index
  4. Store document and chunk metadata

File Ingestion ​

Submit a file for automatic processing:

  1. File is converted to Markdown (using @cognipeer/to-markdown)
  2. Markdown is chunked according to module config
  3. Chunks are embedded and stored

Querying ​

POST /api/client/v1/rag/modules/:key/query
Authorization: Bearer <token>
json
{
  "query": "How do I reset my password?",
  "topK": 5,
  "filter": { "source": "docs" }
}

Pipeline:

  1. Embed the query text
  2. Perform vector similarity search
  3. Return matching chunks with scores and metadata

Response:

json
{
  "matches": [
    {
      "content": "To reset your password, navigate to...",
      "score": 0.92,
      "metadata": { "source": "docs", "documentTitle": "Product FAQ" }
    }
  ]
}

Hybrid retrieval ​

Pure vector search can miss exact terms such as error codes, SKUs, acronyms and proper nouns, because they carry little semantic signal. With Hybrid retrieval a module also runs a keyword search next to the vector search and merges the two rankings.

Turn it on in the module's Retrieval section (step 6 of Create module, and in the module's edit form):

SettingMeaning
Hybrid retrievalRun keyword search alongside the vector search and merge the two rankings.
Merge modeReciprocal rank fusion combines the two rankings by position and ignores the raw scores. Weighted blends the two scores directly, so both have to be on comparable scales.
Dense weight (Weighted mode)0 to 1, in steps of 0.05, default 0.5. 1 is pure vector search, 0 is pure keyword search.
Rank constant (Reciprocal rank fusion)How steeply rank position is discounted: 1 to 1000, default 60. A lower value favours the top few results more heavily.

The switch is available only when the module's vector provider has a keyword index to combine with. These providers do: Azure AI Search, Elasticsearch (Cloud, Self-Hosted and the plain driver), MongoDB Atlas Vector Search, Orama and PostgreSQL (pgvector). On any other provider the switch is disabled and the form says hybrid retrieval is unavailable for that module. The module's detail page shows the current setting under Hybrid Retrieval.

Both rankings are mapped back onto a 0 to 1 score before the result leaves the vector layer, so Min score keeps one scale. Under reciprocal rank fusion that score expresses rank confidence rather than similarity: pick Weighted when an absolute threshold has to keep meaning vector similarity.

Over the API the setting is the module's hybrid object: { "enabled": true, "mode": "weighted", "alpha": 0.5 } or { "enabled": true, "mode": "rrf", "k": 60 }. { "enabled": false } turns it off.

Attaching knowledge bases to an agent ​

An agent can search several Knowledge Engine modules. In the agent editor, add one row per module under Knowledge Engine:

FieldMeaning
keyThe Knowledge Engine module.
descriptionTells the model when to use it ("Use for: HR policies"). Strongly recommended with more than one module.
topK, minScoreOptional per-module overrides. When unset, the module's own defaults apply.
filterOptional fixed metadata filter, AND-ed with any filter the model supplies.
enabledSet to false to keep the row but stop using it.

The agent setting knowledgeToolMode chooses the tool surface:

  • combined (default): one knowledge_search queries every enabled module at once. Hits are merged by score (the best 10 overall) and tagged [kb: <key>, documentId: ..., file: ..., score: 0.xx]. One knowledge_read_document and knowledge_read_document_lines pair takes an optional kb argument, and the document must belong to a bound module.
  • separate: each module gets its own tools, suffixed with the module key (knowledge_search_<key>, knowledge_read_document_<key>, and so on), with the row's description added to the tool description.

The rows are stored as knowledgeBindings. The older single knowledgeEngineKey still works and is treated as one binding. When both are present, knowledgeBindings wins. Modules that are not visible to the agent's project are skipped with a warning.

Showing the sources of an answer ​

An agent's Show sources setting can list the knowledge base documents an answer relied on: Cited by the model lists the ones the model marks with [1], Retrieved sources lists what the search returned, with the score of each document's best passage. The score threshold and the passages per search come from the binding's own topK and minScore. See Showing sources.

An agent that answers from a knowledge base also keeps its sessions personal: see Knowledge base access control.

Text extraction and OCR ​

Files that you upload to a knowledge base are turned into text by the console's single extraction engine, the same one that serves the Document Store, agent attachments and the crawler. The create and edit forms of a knowledge base have an Extraction section with the shared OCR fields: Read scanned pages (OCR) (Off, Auto (scanned pages only) or Every page), Engine (a project OCR or vision model, or the bundled offline Local engine (CPU, Tesseract)), Languages, Maximum pages per document and Also read images. OCR is off by default. The field descriptions are in OCR jobs.

The setting applies to files uploaded from now on. Re-indexing never reads a file again; use Re-extract on a document to read its stored original with the current setting.

Documents Tab ​

The Documents tab of a module lists its documents newest first, in pages. Use the search box to find a document by file name, the status filter (pending, processing, indexed, failed) to narrow the list, and the pager to change the page size. Re-index All applies to the whole module, not only the page you see.

API clients must page

The dashboard route GET /api/rag/modules/:key/documents no longer returns every document. It answers { documents, total, limit, offset } and takes search, status, limit and offset. The default page is 25 documents and the maximum is 100. Rows no longer carry the inline source text. A script that assumed one call returns the whole list must now loop over offset until it has total documents. The client API route GET /api/client/v1/rag/modules/:key/documents is unchanged.

Test and tune retrieval ​

A module's page has the tabs Overview, Documents, Playground, Usage and History (and Access when access control is on). Three of them help you check that retrieval returns what your users need.

Playground ​

The Playground tab (Query Playground) asks a question against the module. Cognipeer embeds the query, searches the vector index and shows the most relevant chunks. Run it before you bind the module to an agent, and again after every change that affects retrieval: new content, a different chunk size or embedding model, a changed Min score or hybrid retrieval.

FieldMeaning
QueryThe question, worded the way your users will ask it.
Min score0 to 1. Matches below it are discarded.
Metadata filter (JSON)Optional. A bare value means equality. The operators $eq, $ne, $gt, $gte, $lt, $lte, $in, $nin and $exists combine with $and, $or and $not. When the module lists filterable fields, the field shows them.
Top KHow many matches to return, 1 to 100.

Search shows the number of matches and the latency, then one entry per match with its file name and Score. A score of 0.8 or more is shown green, 0.5 to below 0.8 yellow and anything lower red. If the module's Response detail is set to text only, the response carries no scores, ids or metadata, and the Playground says so: switch Response detail to Full to see them.

When an agent answers badly or says it does not know, ask the same question here. If the right chunk is missing or scores low, the problem is in the content or the module settings. If the right chunk comes back with a good score, look at the agent's instructions and its knowledge binding instead.

Overview ​

The Overview tab shows the counters Documents, Chunks, Total Queries, Avg Latency, Zero-result queries (nothing was retrieved at all) and Filtered by min score (matches were found, but the threshold discarded them). Below them:

  • Score distribution plots the best score of every logged query against the module's minimum score. If many queries sit just under the line, the minimum is probably too high.
  • Queries that found nothing lists the questions the module had no answer for. Each one means the content is missing or Min score is set too high. Without Knowledge Engine admin access you see only your own queries.

History ​

The History tab (Query History) lists the last 50 recent queries against the module. A knowledge base administrator sees everyone's queries, anyone else sees their own.

Make content easier to find ​

  • Keep related facts together under a clear heading. A chunk that is a fragment of a table or a list scores low for the question it answers.
  • Put the words people use into the text, and add them as metadata when you filter on them. If exact terms such as product codes matter, turn on hybrid retrieval.
  • Remove duplicate and outdated documents. They compete with the current answer.
  • Keep the content current: re-ingest a changed document, or put a crawler or a connector source on a schedule.

Export and Import ​

Move the documents of a module to another module, project or environment. Use Export and Import in the toolbar of the Documents tab.

Export downloads <module-key>.rag.zip. The ZIP holds one or more JSONL parts named <module-key>.part-001.rag.jsonl, <module-key>.part-002.rag.jsonl and so on, with 150 documents in each part. The first line of each part is a header (format: "cognipeer.rag-module", version: 1, the export time, the module key, name and description, documentCount and skippedDocuments for the whole export, and the part index, count and document count). Each following line is one document:

json
{"type":"document","fileName":"handbook.md","contentType":"text/markdown","metadata":{"team":"hr"},"chunkConfig":{},"content":"# Handbook ..."}

What is exported is each document's file name, content type, metadata, chunk settings and source text. Empty values are left out of the line. Vectors and chunks are not exported, because they belong to the embedding model of the module. A document with no loadable source text is not written and is counted in skippedDocuments.

Import reads JSONL files into the module you are on. Unzip the export first, then select the part files. You can select several files at once; the console imports them in name order (part-001, part-002, ...), whatever order the file picker returns. The documents are re-chunked and re-embedded with that module's settings and queued for indexing. Content that did not change is skipped, so importing the same file twice does not duplicate anything. The screen shows Import finished: N of M document(s) queued, K failed. Each file goes up in batches of 1000 lines.

  • The header line is optional. A plain file of {"fileName": "...", "content": "..."} lines imports too. Older exports (a single .rag.jsonl file, or lines with "chunkConfig": null) still import.
  • A header with a version other than 1 is refused.
  • One request takes at most 5000 documents. The dashboard splits large files for you; an API caller must do it.
  • The module must exist and be active.
  • Bad lines are reported with their line number and do not stop the rest (for example fileName is required).
  • When access control is on for the knowledge base, exporting and importing need Knowledge Engine admin. An administrator whose own reads are checked exports only the documents they may read.
RoutePurpose
GET /api/rag/modules/:key/exportDownload the module as application/zip (<module-key>.rag.zip)
POST /api/rag/modules/:key/importBody { "data": "<JSONL text>" }, one part (or a batch of it) per request. Answers { total, imported, failed, errors }

Access control ​

A knowledge base can decide who reads each document: switch Enforce document permissions on in the Access tab, organise documents in folders, and give folders and documents their own permissions for everyone, people, groups, e-mail addresses, API tokens and external directory people. Every read path follows the caller. See Knowledge base access control.

Re-ingestion ​

When a document is updated or chunking config changes, use reingestDocument() to:

  1. Remove existing vectors for the document
  2. Re-chunk with current settings
  3. Re-embed and store new vectors

Dependencies ​

The Knowledge Engine pipeline integrates several control plane services:

  • Inference Service — For generating embeddings
  • Vector Service — For storing and querying vectors
  • File Service — For file conversion (optional)

Metadata Filtering ​

Queries accept a filter in the console's canonical filter language, which the control plane pushes down to the vector store — see Vector Stores → Metadata Filtering for the operator list and per-provider support.

A module can also carry its own filter configuration:

SettingEffect
defaultFilterANDed into every query against the module. Lets several sources share one vector index while each module retrieves only its own slice.
filterableFieldsMetadata keys callers may filter on. A query touching any other key is rejected with 400. The list is also surfaced to agents and MCP clients as the filter argument's documentation, so a model knows what it may narrow by.
bash
curl -X POST "$CONSOLE_URL/api/client/v1/rag/modules/support-kb/query" \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "query": "how do I reset my password?",
    "topK": 5,
    "filter": { "source": "crawler", "depth": { "$lte": 2 } }
  }'

A filter the underlying vector store cannot push down is rejected rather than ignored, so a filtered query never silently returns unfiltered passages.