# What Are the Six Types of Persistent Memory for AI Agents and How to Implement Them

> Explore six types of persistent memory for AI agents including working, episodic, semantic, procedural, graph, and vector. Learn implementation with Spring AI and Oracle Database 23ai.

- Repository: [Oracle Developers/oracle-ai-developer-hub](https://github.com/oracle-devrel/oracle-ai-developer-hub)
- Tags: deep-dive
- Published: 2026-05-10

---

**AI agents require a hierarchy of six distinct persistent memory layers—working, episodic, semantic, procedural, graph, and vector-only—to retain context across requests, retrieve domain knowledge, and execute external actions, all of which are demonstrated in the Oracle AI Developer Hub using Spring AI and Oracle Database 23ai.**

The Oracle AI Developer Hub reference architecture defines a comprehensive memory stack that gives AI agents a full-stack "brain." Unlike simple prompt-based systems, this implementation in `apps/oracle-database-java-agent-memory/` leverages relational tables, hybrid vector indexes, and annotated Java methods to create a persistent, queryable memory system that survives application restarts.

## The Six Types of Persistent Memory for AI Agents

The repository categorizes memory into six distinct types, each serving a specific function in the agent's cognitive architecture.

### Working (Short-Term) Memory

Working memory stores the LLM's immediate context window—the tokens supplied for the current inference call. While not persisted to disk, this scratch-pad is implicit in every prompt constructed by the `ChatClient`. According to `apps/limitless-workflow/Limitless/20 Concepts/Working Memory.md`, this layer provides the transient space for current reasoning steps before the response is generated.

### Episodic Memory

Episodic memory retains chronological chat history, including previous user and assistant turns with timestamps. In the Oracle AI Developer Hub, this resides in the `SPRING_AI_CHAT_MEMORY` relational table, as detailed in [`apps/oracle-database-java-agent-memory/docs/articles/ai-agent-memory-spring-ai-oracle.md`](https://github.com/oracle-devrel/oracle-ai-developer-hub/blob/main/apps/oracle-database-java-agent-memory/docs/articles/ai-agent-memory-spring-ai-oracle.md). The `MessageChatMemoryAdvisor` reads the last N rows for the current conversation ID, prepending them to the prompt, then persists new exchanges after the model replies.

### Semantic Memory

Semantic memory stores domain knowledge retrievable by similarity, such as policy documents or code snippets. This implementation uses Oracle AI Database 26ai's hybrid vector index accessed via `DBMS_HYBRID_VECTOR`. As implemented in [`apps/oracle-database-java-agent-memory/docs/articles/ai-agent-memory-spring-ai-oracle-wordpress.md`](https://github.com/oracle-devrel/oracle-ai-developer-hub/blob/main/apps/oracle-database-java-agent-memory/docs/articles/ai-agent-memory-spring-ai-oracle-wordpress.md), this layer enables RAG-style retrieval of facts never mentioned in the current chat.

### Procedural Memory

Procedural memory encapsulates callable tools and functions that perform actions. In the hub, these are Java methods annotated with `@Tool` (e.g., `listOrders`, `getReturnPolicy`) that query the database. The `ChatClient` registers these via `.defaultTools()`, allowing the LLM to invoke external systems rather than generate text responses, as documented in `apps/limitless-workflow/Limitless/20 Concepts/Procedural Memory.md`.

### Graph Memory

Graph memory tracks relationships between entities, such as product hierarchies or supply chains. The architecture supports this through a `CallAroundAdvisor` extension point, described in [`apps/oracle-database-java-agent-memory/docs/todos/graph_knowledge/knowledge_graph_intro.md`](https://github.com/oracle-devrel/oracle-ai-developer-hub/blob/main/apps/oracle-database-java-agent-memory/docs/todos/graph_knowledge/knowledge_graph_intro.md). While marked as a TODO in the current repository, this hook allows injection of graph query results (Gremlin or Cypher) into prompts for multi-hop reasoning.

### Vector-Only Memory

Vector-only memory stores raw embedding vectors for high-throughput similarity search, often used alongside semantic memory but kept separate for performance. The hub implements this in `VECTOR_STORE` tables using Oracle Database 23ai's native vector capabilities, accessible via `DBMS_HYBRID_VECTOR.SEARCH` for pure nearest-neighbor lookup without keyword fusion.

## How to Implement the Memory Layers in Spring AI

The Oracle AI Developer Hub provides concrete implementation patterns using Spring AI advisors and Oracle Database 23ai integrations.

### Configuring Episodic Memory

Create a `MessageChatMemoryAdvisor` that wraps a chat memory repository. This advisor automatically manages conversation state in the `SPRING_AI_CHAT_MEMORY` table:

```java
import org.springframework.ai.chat.memory.MessageChatMemoryAdvisor;
import org.springframework.ai.chat.memory.ChatMemoryRepository;

MessageChatMemoryAdvisor episodicAdvisor = new MessageChatMemoryAdvisor(chatMemoryRepository);
ChatClient client = ChatClient.builder(llm)
    .defaultAdvisors(episodicAdvisor)
    .build();

```

The advisor persists each exchange to the relational table and retrieves the last 100 messages (configurable) based on the conversation ID.

### Setting Up Semantic Memory with Hybrid Search

Configure semantic retrieval using the hybrid vector index. First, load an ONNX embedding model such as `all-MiniLM-L12-v2` inside Oracle AI Database 26ai, then create the hybrid index. Use `OracleHybridDocumentRetriever` with a `RetrievalAugmentationAdvisor`:

```java
import org.springframework.ai.oracle.database.OracleHybridDocumentRetriever;
import org.springframework.ai.rag.retrieval.search.RetrievalAugmentationAdvisor;

OracleHybridDocumentRetriever retriever = new OracleHybridDocumentRetriever(dataSource);
RetrievalAugmentationAdvisor semanticAdvisor = new RetrievalAugmentationAdvisor(retriever);

ChatClient client = ChatClient.builder(llm)
    .defaultAdvisors(semanticAdvisor)
    .build();

```

This advisor fetches top-k relevant documents from the hybrid index and injects them into the system prompt before each LLM call.

### Implementing Procedural Memory Tools

Expose database operations as tool functions using the `@Tool` annotation. The `ChatClient` registers these methods, allowing the LLM to generate structured call requests:

```java
import org.springframework.ai.tool.annotation.Tool;
import org.springframework.jdbc.core.JdbcTemplate;

public class OrderTools {
    private final JdbcTemplate jdbcTemplate;
    
    public OrderTools(JdbcTemplate jdbcTemplate) {
        this.jdbcTemplate = jdbcTemplate;
    }
    
    @Tool
    public String listOrders() {
        return jdbcTemplate.queryForList("SELECT * FROM orders").toString();
    }
}

// Registration
ChatClient client = ChatClient.builder(llm)
    .defaultTools(new OrderTools(jdbcTemplate))
    .build();

```

When the LLM decides to retrieve order data, it invokes `listOrders()`, and the result is returned as context for the final response.

### Querying Vector-Only Storage

For high-performance similarity search without full RAG orchestration, query the vector store directly using SQL:

```sql
SELECT id, score 
FROM DBMS_HYBRID_VECTOR.SEARCH( 
    query_vector => :embed,
    top_k => 10,
    fuse => 'rrf' 
);

```

This bypasses the retrieval advisor for use cases requiring raw vector similarity scores or custom fusion algorithms.

### Extending with Graph Memory

To implement graph memory, create a `CallAroundAdvisor` that intercepts prompts and injects graph traversal results. The repository provides the extension point in [`apps/oracle-database-java-agent-memory/docs/todos/graph_knowledge/knowledge_graph_intro.md`](https://github.com/oracle-devrel/oracle-ai-developer-hub/blob/main/apps/oracle-database-java-agent-memory/docs/todos/graph_knowledge/knowledge_graph_intro.md):

```java
import org.springframework.ai.chat.client.advisor.CallAroundAdvisor;

public class GraphMemoryAdvisor implements CallAroundAdvisor {
    @Override
    public AdvisedResponse aroundCall(AdvisedRequest request, CallAroundAdvisorChain chain) {
        // Execute graph query (e.g., Gremlin) against Neo4j-compatible store
        // Inject results into request messages
        return chain.nextAroundCall(request);
    }
}

```

This advisor enables the agent to traverse entity relationships and answer multi-hop queries beyond vector similarity.

## Summary

The Oracle AI Developer Hub demonstrates a complete persistent memory architecture for AI agents using six complementary layers:

- **Working memory** handles the immediate context window for current inference
- **Episodic memory** persists conversation history in `SPRING_AI_CHAT_MEMORY` tables via `MessageChatMemoryAdvisor`
- **Semantic memory** retrieves domain knowledge using Oracle AI Database 26ai hybrid vector indexes
- **Procedural memory** executes actions through `@Tool` annotated Java methods
- **Graph memory** (extension point) supports entity relationship traversal via `CallAroundAdvisor`
- **Vector-only memory** provides high-speed embedding storage through `DBMS_HYBRID_VECTOR` tables

By wiring these layers together through Spring AI advisors, agents maintain coherent long-term context while leveraging Oracle Database 23ai for enterprise-grade persistence.

## Frequently Asked Questions

### What is the difference between episodic and semantic memory in AI agents?

**Episodic memory stores the chronological sequence of interactions** specific to a conversation session, enabling the agent to recall what was said previously. According to the implementation in [`apps/oracle-database-java-agent-memory/docs/articles/ai-agent-memory-spring-ai-oracle.md`](https://github.com/oracle-devrel/oracle-ai-developer-hub/blob/main/apps/oracle-database-java-agent-memory/docs/articles/ai-agent-memory-spring-ai-oracle.md), this uses relational tables with conversation IDs. **Semantic memory stores factual domain knowledge** independent of any specific chat, retrieved via vector similarity search from hybrid indexes, allowing the agent to access documents or data it was never explicitly told about in the current conversation.

### How does Spring AI's `MessageChatMemoryAdvisor` persist conversation history?

The advisor automatically manages the `SPRING_AI_CHAT_MEMORY` table, reading the last N messages for the current conversation ID before each LLM call and writing the new exchange after the response is generated. As shown in `apps/limitless-workflow/Limitless/20 Concepts/Episodic Memory.md`, this provides transparent persistence without manual database operations in your application code.

### Can vector-only memory replace semantic memory for RAG applications?

**Vector-only memory serves a different purpose than semantic memory.** While semantic memory in the Oracle AI Developer Hub combines vector similarity with keyword search (hybrid retrieval), vector-only storage accessed via `DBMS_HYBRID_VECTOR.SEARCH` provides raw nearest-neighbor lookup optimized for speed. For comprehensive RAG, you typically need the hybrid approach to handle lexical matches (like product SKUs or specific codes) that embedding models might miss, as documented in the hybrid search examples.

### What database version is required for the vector memory implementations?

The hub's vector memory features require **Oracle AI Database 26ai** or later, which includes native `DBMS_HYBRID_VECTOR` support and ONNX runtime integration for embedding generation inside the database. The `OracleHybridDocumentRetriever` and vector storage tables rely on these specific 26ai capabilities for in-database AI operations.