# Cache-Augmented Generation (CAG)

### What It Is

Neko incorporates Cache-Augmented Generation (CAG) as a core component of its AI & Machine Learning infrastructure. CAG provides the **DeFi Multiagent System** with immediate access to essential, pre-loaded strategic knowledge, particularly concerning **yield optimization and risk management heuristics** relevant to the HyperEVM environment.Unlike Retrieval-Augmented Generation (RAG) which fetches dynamic data in real-time, CAG focuses on providing agents with foundational, relatively stable knowledge efficiently.

#### [​](https://docs.neko.fun/cag#purpose%3A-efficient-strategic-context-setting)Purpose: Efficient Strategic Context Setting <a href="#purpose-3a-efficient-strategic-context-setting" id="purpose-3a-efficient-strategic-context-setting"></a>

The primary goal of using CAG within Neko is to **rapidly equip agents with core strategic context** without the latency associated with real-time database lookups for *this specific type* of information. This allows agents to quickly ground their decision-making processes in established best practices and learned heuristics relevant to their assigned tasks (e.g., managing an Earn strategy).

#### [​](https://docs.neko.fun/cag#mechanism%3A-the-cag-database-kv-cache)Mechanism: The CAG Database (KV Cache) <a href="#mechanism-3a-the-cag-database-kv-cache" id="mechanism-3a-the-cag-database-kv-cache"></a>

Neko utilizes a specialized **CAG Database**, likely implemented as a pre-computed **key-value (KV) cache**. This cache contains distilled strategic information relevant to DeFi operations on HyperEVM.

* **Pre-computation:** The knowledge within the CAG DB is processed and stored beforehand.
* **Context Injection:** When an agent requires foundational strategic guidance, the relevant portions of this KV cache are efficiently loaded directly into the agent’s operational **context window**.
* **Efficiency:** This direct injection avoids the need for complex real-time vector searches or embeddings *for this cached knowledge*, making context setting faster, especially for well-defined, constrained knowledge sets.

#### [​](https://docs.neko.fun/cag#content%3A-distilled-defi-knowledge-%26-heuristics)Content: Distilled DeFi Knowledge & Heuristics <a href="#content-3a-distilled-defi-knowledge-26-heuristics" id="content-3a-distilled-defi-knowledge-26-heuristics"></a>

The information stored within Neko’s CAG DB represents **distilled knowledge and effective heuristics** derived from analyzing successful DeFi strategies and risk management principles (drawing inspiration from the vast landscape of techniques outlined in Neko’s research context). This includes:

* Core principles for managing specific strategy types.
* Effective patterns for liquidity provision or borrowing strategies on HyperEVM.
* Key risk parameters or safe operational boundaries.
* Learned heuristics from past agent performance.

This is *not* raw, real-time data but rather a condensed, readily accessible library of strategic “rules of thumb” or foundational knowledge.

#### [​](https://docs.neko.fun/cag#synergy-with-rag)Synergy with RAG <a href="#synergy-with-rag" id="synergy-with-rag"></a>

CAG and RAG work in tandem to provide agents with comprehensive context:

* **CAG:** Provides the **foundational strategic knowledge** and heuristics (the “how-to” based on learned patterns).
* **RAG:** Provides the **real-time, dynamic data** (current market prices, specific protocol states, recent events).

By feeding both the pre-loaded CAG context and the real-time RAG data into the agent’s decision-making process (e.g., the LLM core), Neko ensures that actions are both strategically sound and responsive to the immediate on-chain environment.

#### [​](https://docs.neko.fun/cag#outcome)Outcome <a href="#outcome" id="outcome"></a>

Leveraging CAG allows Neko agents to make **faster, more informed decisions** by instantly accessing a pre-loaded cache of relevant strategic heuristics. This efficiency, combined with the real-time data provided by RAG, enables the DeFAI Multiagent system to operate effectively and adaptively within the dynamic HyperEVM ecosystem, optimizing for yield and managing risk according to both established best practices and current market conditions.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.neko.fun/architecture/ai-ml-architecture/cache-augmented-generation-cag.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
