botserver/docs/src/chapter-03/caching.md

1.2 KiB
Raw Blame History

Caching (Optional)

Caching can improve response times for frequently accessed knowledgebase queries.

InMemory Cache

The bot maintains an LRU (leastrecentlyused) cache of the last 100 FIND results. This cache is stored in the bots process memory and cleared on restart.

Persistent Cache

For longerterm caching, the gbkb package can write query results to a local SQLite file (cache.db). The cache key is a hash of the query string and collection name.

Configuration

Add the following to .gbot/config.csv:

key,value
cache_enabled,true
cache_max_entries,500

Usage Example

SET_KB "company-policies"
FIND "vacation policy" INTO RESULT   ' first call hits VectorDB
FIND "vacation policy" INTO RESULT   ' second call hits cache
TALK RESULT

The second call returns instantly from the cache.

Cache Invalidation

  • When a document is added or updated, the cache for that collection is cleared.
  • Manual invalidation: CLEAR_CACHE "company-policies" (custom keyword provided by the system).

Benefits

  • Reduces latency for hot queries.
  • Lowers load on VectorDB.
  • Transparent to the script author; caching is automatic.