Integrate Semantic Cache with Hermes

Updated at:

This topic describes how to integrate the Tair Semantic Cache gateway (OpenAI-compatible mode) with Hermes Agent, enabling millisecond-level responses for AI conversations in semantically similar scenarios. The entire process takes approximately 3 minutes.

Prerequisites

Prerequisite

Description

Semantic Cache instance

A Semantic Cache instance is created and is in the Running state. If you have not created one, see Semantic cache instance setup.

Connection information

The Base URL and API Key have been obtained.

Hermes Agent

Hermes Agent is installed and can communicate with a large language model (LLM).

Step 1: Obtain the Semantic Cache connection information

  1. Log on to the Tair console. In the left-side navigation pane, click Tair Semantic Cache Gateway Instance.

  2. In the instance list, click the name of the target instance to go to the instance details page.

  3. In the Access Information section, obtain the following information:

    Item

    Description

    Example

    Endpoint / Base URL

    Used to replace the model service address in OpenClaw.

    https://tg-bp1******.redis.rds.aliyuncs.com

    API Key

    Used for authentication.

    sk-****

Note

If you want to access the instance over the Internet, such as from a local development machine, click the Request button next to Public Access in the Network Access section. After the application is approved, the Base URL changes to a public endpoint. The API key remains unchanged. Select the address that matches your network environment.

Step 2: Modify the Hermes Agent configuration

The configuration file and key file of Hermes Agent must be edited by using a terminal (command line).

Open a terminal:

  • macOS: Press Command + Space to open Spotlight Search, type Terminal, and press Enter.

  • Windows: Press Win + R, type cmd or powershell, and press Enter.

Locate the configuration file:

The configuration directory of Hermes Agent is typically located in the .hermes folder under the home directory. If you are not sure about the installation path, run the following commands to find it:

# Method 1: Check the default location
ls ~/.hermes/config.yaml

# Method 2: If the default location does not exist, search globally
find / -name "config.yaml" -path "*/.hermes/*" 2>/dev/null

After locating the directory, confirm the actual paths of the following two files:

  • Main configuration file: <Hermes directory>/config.yaml

  • Key file: <Hermes directory>/.env

Note

In most cases, Hermes is installed in ~/.hermes/ (the .hermes folder under the home directory). ~ typically resolves to /Users/<username> on macOS/Linux, and C:\Users\<username> on Windows. If Hermes is installed in a different location, replace ~/.hermes/ with the actual path in the following steps.

1. Add the API Key

Add the API Key of Semantic Cache to the ~/.hermes/.env file:

echo 'SEMANTIC_CACHE_API_KEY=sk-xxxxxx' >> ~/.hermes/.env

Replace sk-xxxxxx with your actual Semantic Cache API Key.

2. Add a provider and switch the model

Edit ~/.hermes/config.yaml, add a Semantic Cache provider under custom_providers, and point model to it:

custom_providers:
  - name: semantic-cache
    base_url: https://tg-xxxxxx.redis.rds.aliyuncs.com/compatible-mode/v1
    key_env: SEMANTIC_CACHE_API_KEY

model:
  default: qwen3.6-plus
  provider: semantic-cache

Parameter description:

Parameter

Description

name

The custom provider name. You can specify any name.

base_url

The endpoint of the Semantic Cache instance. The /compatible-mode/v1 path must be appended.

key_env

The name of the environment variable that stores the API Key in the .env file.

model.default

During the public preview, only qwen3.6-plus is supported.

model.provider

Must match the name value in custom_providers.

Complete configuration example (adding Semantic Cache while keeping the existing provider):

custom_providers:
  - name: my-original-provider
    base_url: https://your-original-endpoint.com/v1
    key_env: ORIGINAL_API_KEY
  - name: semantic-cache
    base_url: https://tg-xxxxxx.redis.rds.aliyuncs.com/compatible-mode/v1
    key_env: SEMANTIC_CACHE_API_KEY

model:
  default: qwen3.6-plus
  provider: semantic-cache
Note

You do not need to delete the existing provider configuration. Hermes supports multiple providers. You can specify the provider to use by setting model.provider. To switch back to the original provider, modify model.provider and model.default.

Step 3: Verify that the configuration takes effect

Hermes Agent loads the configuration file in real time. You do not need to restart the service. Start a new conversation to proceed.

hermes

Verify the cache

Verify by using Hermes conversations

  1. Send a question in Hermes. For example: What is Redis Cluster?

  2. Wait for the response. The first request calls the LLM and typically takes tens of seconds.

  3. Exit the conversation and start a new one (or open a new session). Send a semantically similar but differently worded question: Explain Redis Cluster

  4. Observe the response time. If the cache is hit, the second response is returned in milliseconds, and the content is the same as the first response.

Verify by using curl

You can also bypass Hermes and send requests directly to the Semantic Cache instance for verification.

First request (write to cache):

curl "https://<Base URL>/compatible-mode/v1/chat/completions" \
  -H "Authorization: Bearer <API Key>" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "qwen3.6-plus",
    "messages": [{"role": "user", "content": "What is Redis Cluster"}]
  }'

Second request (verify cache hit):

curl "https://<Base URL>/compatible-mode/v1/chat/completions" \
  -H "Authorization: Bearer <API Key>" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "qwen3.6-plus",
    "messages": [{"role": "user", "content": "Explain Redis Cluster"}]
  }'

If the cache is hit, the response time of the second request is reduced from tens of seconds to milliseconds.

Usage notes

Item

Description

Public and internal endpoints

The public endpoint and internal endpoint are different. Make sure that you use the endpoint that matches your network environment. The API Key is not affected.

Model support

During the public preview, only qwen3.6-plus is supported for the model parameter.

Switching between providers

Modify model.provider to switch providers. You do not need to delete other provider configurations.

Cache matching scope

Semantic Cache extracts the last user message for matching by default. The tools parameter in Hermes does not affect cache matching.

Context requirements

Hermes requires a model with a context window of at least 64K tokens. qwen3.6-plus meets this requirement.

Related operations

  • Adjust the similarity threshold: A lower threshold increases the hit rate but may cause false matches. A higher threshold improves precision but reduces the hit rate. You can adjust the threshold in the plug-in configuration in the console. The default value is 0.85.

  • Configure the cache TTL: Set an appropriate TTL for scenarios where answers may become outdated.

  • Configure index fields (index_from): By configuring index fields, you can filter cache data and implement multi-tenant isolation. Cache data with different index values is isolated from each other.

  • Switch back to the original provider: Modify model.provider and model.default in config.yaml to point to the original provider.

  • View the complete API capabilities: See Technical architecture and API.