Ajmax76 opened a new issue, #14241:
URL: https://github.com/apache/apisix/issues/14241

   ### Description
   
   As a platform engineer running agentic / MCP workloads through APISIX, I 
want an optional deterministic slot-isolation pre-filter ahead of L2 semantic 
lookup in `ai-cache`, so that parameterized `tool_calls` can be cached safely 
without cross-tenant argument leaks or dropping to a 0% exact-match hit rate.
   
   ### Problem
   The `ai-cache` plugin's two-layer design (L1 exact SHA-256 + L2 Redis Stack 
semantic search) works well for general Q&A, but agentic / MCP workloads with 
parameterized `tool_calls` hit a catch-22—even with `include_consumer: true` 
enabled:
   
   1. **L1 Exact-Match (`layers: ["exact"]`):** Safe, but drops to **0.0% hit 
rate** whenever a per-request ID (`charge_id`, `order_id`, `pod_id`) changes.
   2. **L2 Semantic (`layers: ["exact", "semantic"]`):** Dense embedding models 
treat alphanumeric entity IDs as minor surface noise. Even above a strict 
`similarity_threshold: 0.95`, two requests from the same route/consumer collide 
and replay stale arguments inside `tool_calls[].function.arguments`:
      - **ID swap (`0.9749` cosine similarity):** `Refund 4,500 cents on charge 
'ch_99102000112201' for reason "card declined at checkout"!` vs `...charge 
'ch_3MtwBwLkdI9999'...` hits L2 and returns `ch_99102000112201`.
      - **Negation bypass (`0.9896` cosine similarity):** `Do NOT refund 4,500 
cents on charge 'ch_99102000112201'...` collides with the positive cached 
refund command.
   
   ### Standalone Benchmark (1,000 Dynamic-ID & Adversarial Calls)
   Reproduction harness across 10 standard semantic/lexical cache architectures:
   https://github.com/ajmax76/mcp-tool-cache-benchmark
   
   | Engine / Architecture | Cache Hits | Exact Args | Stale Args Returned | 
Cold CPU Latency |
   | :--- | :--- | :--- | :--- | :--- |
   | Exact SHA-256 | 0 / 1,000 | 0 (0.0%) | 0 | 2.2 µs |
   | `all-MiniLM-L6-v2` | 732 / 1,000 | 0 (0.0%) | 732 | 14,600.3 µs |
   | `BAAI/bge-small-en-v1.5` | 839 / 1,000 | 0 (0.0%) | 839 | 27,420.6 µs |
   | `thenlper/gte-small` | 839 / 1,000 | 0 (0.0%) | 839 | 166,089.9 µs |
   | `intfloat/e5-small-v2` | 799 / 1,000 | 0 (0.0%) | 799 | 26,129.6 µs |
   
   ### Proposed Enhancement
   Add an optional **deterministic slot-isolation pre-filter** ahead of L2 
semantic lookup in `ai-cache`:
   - Extract high-entropy entity IDs, numeric amounts, and negation/polarity 
tokens before cache resolution.
   - Match on the normalized intent template and deterministically re-bind the 
live request's extracted values into `tool_calls[].function.arguments` on hit 
(failing open cleanly to upstream on negation or ambiguous coreference).
   
   Since APISIX runs on OpenResty/LuaJIT, a zero-dependency C shared library 
called via **LuaJIT FFI** avoids embedding round-trips completely—in the 
1,000-call harness above, our C pre-filter runs at **12.8 µs p50** with **0 
stale arguments returned**.
   
   Happy to share the LuaJIT FFI technical brief or benchmark any `ai-cache` 
prototype against the 1,000-call suite if this fits the roadmap.


-- 
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