AI Semantic Cache

AI License Required

Set up with OpenAI and Redisv3.8+

Enable AI Semantic Caching with OpenAI embeddings API and a Redis vector database.

If you use the text-embedding-ada-002 as an embedding model, you must set a fixed dimension of 1536, as required by the official model specification. Alternatively, use the text-embedding-3-small model, which supports dynamic dimensions and works without specifying a fixed value.

Prerequisites

  • The AI Proxy or AI Proxy Advanced plugin is enabled

  • An OpenAI account

  • A Redis instance.

  • Port 6379, or your custom Redis port is open and reachable from Kong Gateway.

Environment variables

  • OPENAI_API_KEY: Your OpenAI API key

  • REDIS_HOST: The host where your Redis instance runs

Set up the plugin

Add this section to your declarative configuration file:

_format_version: "3.0"
plugins:
  - name: ai-semantic-cache
    config:
      embeddings:
        auth:
          header_name: Authorization
          header_value: Bearer ${{ env "DECK_OPENAI_API_KEY" }}
        model:
          provider: openai
          name: text-embedding-3-large
          options:
            upstream_url: https://api.openai.com/v1/embeddings
      vectordb:
        dimensions: 3072
        distance_metric: cosine
        strategy: redis
        threshold: 0.1
        redis:
          host: ${{ env "DECK_REDIS_HOST" }}
          port: 6379
Copied to clipboard!

Did this doc help?

Something wrong?

Help us make these docs great!

Kong Developer docs are open source. If you find these useful and want to make them better, contribute today!