Skip to content

Knowledge Bases and Isolation

A knowledge base is implemented as a private LibreChat Agent, a matching access-control group, and a disjoint set of attached file IDs. The Agent is the unit a user selects before querying a company or project corpus.

Current knowledge bases

Agent Access group Files Tools
Test Archive KB - Test Archive 41 file_search
Bauer Kompressoren KB - Bauer Kompressoren 373 file_search, protected Bauer Twin MCP tool

The administrator belongs to both groups. Other users should be added only to the groups whose material they are permitted to access.

The provisioning acceptance test verified:

  • all 414 files were embedded;
  • file associations matched their expected Agent;
  • the two Agent file-ID sets had an empty intersection;
  • each Agent answered a corpus-specific grounded query;
  • neither Agent was public.

Selecting a knowledge base

  1. Start a new LibreChat conversation.
  2. Select Test Archive or Bauer Kompressoren from the Agent selector.
  3. Confirm the selected Agent name above the conversation.
  4. Ask the question.
  5. Start a new conversation before changing company or project.

The selected Agent searches only its attached files. Starting a new conversation also prevents history from the previous project remaining in the model prompt.

Creating another company or project

Use a separate isolation unit for every corpus:

  1. Create KB - <company or project>.
  2. Add only authorized users to that group.
  3. Create one private Agent named for the company or project.
  4. Configure RapidDraft Local AI, local/qwen-coder, and file_search.
  5. Attach only the new corpus's files.
  6. Share the Agent with its matching group as agent_viewer.
  7. Verify every file reached the embedded state.
  8. Compare file IDs with all existing Agents and require an empty intersection.
  9. Run grounded positive queries and an out-of-scope query.
  10. Record the corpus owner, source, update method, retention requirement, and last verification date.

Do not reuse another Agent's file associations. Do not make a customer Agent public.

Provisioning automation

scripts/provision-knowledge-bases.ps1 provides the repeatable workflow. It:

  • authenticates with the encrypted administrator credential;
  • creates or updates the two access groups and Agents;
  • resumes uploads by checksum;
  • repairs interrupted committed uploads;
  • rejects duplicate remote filenames;
  • validates embedding completion and file counts;
  • verifies disjoint file IDs;
  • optionally runs grounded chat tests.

Validation without re-uploading files:

.\scripts\provision-knowledge-bases.ps1 -SkipUploads -RunQueryTests

Full resume-safe synchronization:

.\scripts\provision-knowledge-bases.ps1 -RunQueryTests

The local resume state is bound to the canonical Railway hostname. This prevents recorded file IDs from being applied accidentally to another LibreChat installation.

Answering rules

Both Agents are instructed to:

  • search their attached files before answering factual questions;
  • cite filenames and available page or section references;
  • state when an answer was not found;
  • avoid filling gaps from another company or general model knowledge.

The Bauer Agent is additionally limited to two focused file searches per turn and uses the structured tool for project, part, and compatibility queries.

These instructions improve behaviour but are not a security boundary. Enforcement comes from private Agent permissions, group membership, and disjoint file associations.

Logical and physical isolation

The current design provides logical isolation inside one LibreChat installation:

Isolated Shared
Agent definition LibreChat application
Group membership MongoDB service and volume
File associations RAG API
Tool assignment PostgreSQL service and volume
Conversation started with the selected Agent Meilisearch service and volume
Agent instructions S3 bucket and encryption domain

Use a separate LibreChat/RAG stack when a contract or regulation requires independent administrators, encryption keys, backups, regions, databases, or incident boundaries.

Large-corpus retrieval

The stock LibreChat runtime inserted every Agent filename into hidden model instructions and sent one RAG query per file. For the 373-file Bauer corpus, the filename block measured 19,378 characters and 13,270 tokens with the deployed Qwen tokenizer.

The deployed batch-search overlay replaces the filename block with a compact document count and searches the authorized Agent corpus in one RAG request. Filenames remain available in the returned citations, while authorization still uses the private Agent, access group, MongoDB permission filter, Agent namespace, and exact file-ID allow-list.

The change did not alter the knowledge-base selection workflow or re-ingest any files. Its implementation and request path are documented in File Search and RAG Request Flow.

Sources

  • D:\02_Code\LibreChat_Setup\scripts\provision-knowledge-bases.ps1
  • D:\02_Code\LibreChat_Setup\scripts\prepare-bauer-corpus.py
  • D:\02_Code\LibreChat_Setup\README.md
  • D:\02_Code\00_Project_Management_n_skills\01_tracks\rapiddraft-studio\plans\260720_librechat-rapiddraft-integration\README.md