Documentation Index
Fetch the complete documentation index at: https://docs.knowledgestack.ai/llms.txt
Use this file to discover all available pages before exploring further.
Overview
Knowledge Stack uses PostgreSQL’spg_prewarm extension to load frequently accessed tables and indexes into memory when the database starts. This eliminates cold-start latency and ensures fast query performance from the moment your instance is ready.
The most performance-critical operations — chunk retrieval, vector search, and folder/document listing — all benefit from prewarming.
What Gets Prewarmed
The following data is loaded into PostgreSQL’s shared buffers, ordered by access frequency:| Priority | Data | Why It Matters |
|---|---|---|
| 1 | Path hierarchy (table + indexes) | Powers all folder and document navigation |
| 2 | Embedding indexes | Enables fast vector similarity search |
| 3 | Chunk metadata | Needed for every content retrieval operation |
| 4 | Chunk content | Contains the actual text returned to users |
| 5 | Document metadata | Used in document listings and search results |
| 6 | Folder metadata | Used in folder navigation |
| 7 | Document versions | Accessed alongside documents for version info |
| 8 | Sections | Used for navigating within documents |
Running the Prewarm
To manually trigger cache prewarming, run the following SQL:Automatic Prewarming on Startup
To prewarm automatically when your database starts, add the following to your database initialization script:Docker Compose Integration
If you run PostgreSQL via Docker Compose, you can add an init script: docker-compose.yml:Performance Considerations
Memory Impact
- Each page loaded is 8KB
- Prewarming uses PostgreSQL’s
shared_bufferssetting - If
shared_buffersis too small, prewarming may evict other cached data - Recommendation: Set
shared_buffersto at least 256MB. A common guideline is 25% of total system RAM.
When to Prewarm
- After a cold start: The most important time to prewarm — restores fast query performance immediately
- After database migrations: When new data structures or indexes are created
- On a schedule: Periodically (e.g., nightly) if your workload frequently evicts cached data
Monitoring Cache Usage
To see how much space your tables and indexes occupy:Troubleshooting
”function knowledgestack.prewarm_cache() does not exist”
The prewarm function is created by a database migration. Ensure all migrations have been applied to your database.”extension pg_prewarm does not exist”
Thepg_prewarm extension should be created automatically by the migration. You can verify it exists:
“permission denied for function pg_prewarm”
Your database user needs superuser privileges or thepg_read_all_data role to execute pg_prewarm.
