Retrieval-Augmented Generation (RAG) is a critical component of Neko’s AI & Machine Learning infrastructure, responsible for providing Neko agents with real-time, dynamic context about the Hyperliquid ecosystem and broader market conditions. This ensures agent decisions are grounded in the most current information available.

Unlike Cache-Augmented Generation (CAG) which provides foundational strategic knowledge, RAG focuses on fetching up-to-the-moment data points relevant to an agent’s immediate task.

Core Function: Dynamic Context Retrieval

The primary function of the RAG system within Neko is to dynamically retrieve specific, timely data points when requested by an agent during its decision-making workflow. This allows agents to react intelligently to rapidly changing on-chain and off-chain events.

Data Sources & Content

The RAG system ingests and makes accessible a wide array of real-time data crucial for DeFi operations, including:

  • Hyperliquid L1 Order Book Data: Near real-time snapshots from HyperDash, such as best bid/ask, recent trades, volume, and significant depth changes.
  • HyperEVM On-Chain Metrics: Data parsed directly from HyperEVM blocks, including:
    • Token movements (USDC inflow/outflow).
    • Protocol interactions (vault deposits, AMM swaps).
    • Key performance indicators (TVL changes, supply/borrow rates).
    • Transaction volumes for specific applications or assets.
    • Significant event flags (large liquidations on EVM protocols).
  • Order Book Event Flags: Detection of large liquidations or unusual activity directly on the Hyperliquid order book.
  • External Metrics: Aggregated data from trusted sources like DeFiLlama (overall protocol TVL, fees, revenue).
  • (Future) Embedded Data: While the primary focus is real-time metrics, the underlying system (as per PRD) might also incorporate vector embeddings from textual data (news, sentiment) for multi-modal retrieval in advanced scenarios, though rapid retrieval often prioritizes structured metrics.
  • (Future) Model Context Protocol (MCP) Integration for RAG: Future plans involve enhancing the RAG system by adopting MCP.
    • This utilizes specialized servers for dedicated data sources (like HyperEVM application states or order book data), aiming for significant improvements in retrieval speed (via caching, parallelism), flexibility (handling diverse data types), and overall efficiency of providing dynamic context to Neko agents.

Mechanism: Low-Latency Retrieval via Redis

Neko’s RAG implementation prioritizes extremely fast data access to support real-time agent decisions, aiming for sub-100ms query responses for critical lookups.

  1. Agent Query: When an agent (e.g., within the DeFi Multiagent System) requires current data to inform its planning or execution (e.g., “What is the current USDC borrow rate on Protocol X?”, “Any large liquidations on ETH-PERP in the last minute?”), it queries the RAG system.
  2. Redis Lookup: The system heavily leverages Redis as a high-speed, in-memory caching and retrieval layer. Redis stores the latest values for frequently accessed, time-sensitive data points ingested by the backend pipeline.
  3. Data Provision: Redis serves the requested data point(s) back to the agent with minimal latency.
  4. Context Integration: The agent integrates this retrieved real-time data with its existing context (potentially including foundational knowledge from CAG) to make an informed decision or action.

Underlying Technology & Pipeline

While Redis serves as the critical component for achieving low-latency retrieval, it operates as part of a broader data ingestion and processing pipeline (detailed in the RAG DB design). This pipeline handles:

  • Connecting to diverse data sources (HyperEVM nodes, HyperDash feeds, external APIs).
  • Processing, potentially aggregating, and validating incoming data.
  • Feeding the processed, real-time metrics into Redis for fast access.
  • Potentially storing data in more persistent backend databases (like Graph databases as explored in the PRD) for historical analysis, complex relationship queries, or data not suited for Redis caching.

Synergy with CAG

Retrieval-Augmented Generation (RAG) and Cache-Augmented Generation (CAG) are designed to work synergistically, providing Neko agents with a complete and efficient contextual understanding:

  • RAG: Delivers the real-time, dynamic data essential for reacting to current market conditions and specific events (e.g., latest prices, current TVL, recent liquidations). It answers the question “What is happening right now?”.
  • CAG: Provides the foundational strategic knowledge and learned heuristics, efficiently loaded into the context (e.g., best practices for a vault type, core risk parameters). It answers the question “Based on established knowledge, how should I approach this situation?”.

By combining the immediate, volatile data retrieved via RAG with the stable, foundational strategic context provided by CAG, Neko agents can make decisions that are both highly responsive to the present moment and grounded in sound, established strategies. This dual approach allows for intelligent actions that balance tactical adaptation with strategic consistency.

Outcome

The RAG system, with Redis at its core for fast access, empowers Neko agents to operate with up-to-the-second awareness of the dynamic Hyperliquid environment. By providing timely and accurate real-time data, RAG enables more effective, contextually relevant, and potentially safer automated DeFi strategies, allowing agents to adapt quickly to market shifts, seize opportunities, and manage risk effectively.