janiussyafiq commented on code in PR #13308:
URL: https://github.com/apache/apisix/pull/13308#discussion_r3170857202


##########
docs/en/latest/plugins/ai-cache.md:
##########
@@ -0,0 +1,1085 @@
+---
+title: ai-cache
+keywords:
+  - Apache APISIX
+  - API Gateway
+  - Plugin
+  - ai-cache
+description: The ai-cache Plugin caches LLM responses in Redis so identical or 
semantically similar prompts are served from cache, reducing latency and 
upstream cost.
+---
+
+<!--
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+-->
+
+<head>
+  <link rel="canonical" href="https://docs.api7.ai/hub/ai-cache"; />
+</head>
+
+import Tabs from '@theme/Tabs';
+import TabItem from '@theme/TabItem';
+
+## Description
+
+The `ai-cache` Plugin caches LLM responses in Redis so identical or 
semantically similar prompts are served from cache instead of incurring another 
upstream call. It supports two cache layers: an exact-match layer (`exact`) 
keyed by a hash of the prompt, and a semantic layer (`semantic`) that compares 
prompt embeddings via Redis Stack vector search. Either layer can be enabled 
independently, and a hit on the semantic layer backfills the exact layer so 
subsequent identical prompts return immediately.
+
+The Plugin should be used together with [ai-proxy](./ai-proxy.md) or 
[ai-proxy-multi](./ai-proxy-multi.md) on the same Route. The semantic layer 
requires Redis Stack with the RediSearch module and an embedding provider 
(OpenAI or Azure OpenAI).
+
+## Plugin Attributes
+
+| Name | Type | Required | Default | Valid values | Description |
+| --- | --- | --- | --- | --- | --- |
+| `layers` | array[string] | False | `["exact", "semantic"]` | `"exact"`, 
`"semantic"` | Cache layers to enable, queried in order. |
+| `exact.ttl` | integer | False | `3600` | ≥ 1 | Time-to-live in seconds for 
exact-layer entries. |
+| `semantic.similarity_threshold` | number | False | `0.95` | 0–1 | Minimum 
cosine similarity required for a semantic-layer hit. |
+| `semantic.ttl` | integer | False | `86400` | ≥ 1 | Time-to-live in seconds 
for semantic-layer entries. |
+| `semantic.embedding.provider` | string | True (if semantic enabled) | | 
`"openai"`, `"azure_openai"` | Embedding API provider. |
+| `semantic.embedding.endpoint` | string | True (if semantic enabled) | | | 
HTTPS URL of the embedding API. |
+| `semantic.embedding.api_key` | string | True (if semantic enabled) | | | API 
key for the embedding provider. Stored encrypted. |
+| `semantic.embedding.model` | string | False | | | Embedding model name. Uses 
provider default if omitted. |
+| `cache_key.include_consumer` | boolean | False | `false` | | If `true`, 
partition the cache by consumer name. |
+| `cache_key.include_vars` | array[string] | False | `[]` | | Additional 
`ctx.var` names included in the cache key, for example `["$http_x_tenant_id"]`. 
|
+| `bypass_on` | array[object] | False | | | List of `{header, equals}` rules. 
If any matches, the request bypasses the cache. |
+| `max_cache_body_size` | integer | False | `1048576` | ≥ 1 | Maximum response 
size in bytes to write to cache. Larger responses pass through but are not 
cached. |

Review Comment:
   fixed



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to