# How to Implement Agent Memory Using Memify in Cognee: A Complete Guide

> Learn how to implement agent memory using Memify in Cognee. This guide shows you how to transform knowledge graphs into vector-store-backed memory for fast similarity searches and contextual retrieval.

- Repository: [Topoteretes/cognee](https://github.com/topoteretes/cognee)
- Tags: how-to-guide
- Published: 2026-03-16

---

**Memify is Cognee’s core enrichment pipeline that transforms knowledge graphs into vector-store-backed memory, enabling agents to perform fast similarity searches and retrieve contextual triplets from past interactions.**

Cognee (topoteretes/cognee) provides a structured framework for building agent memory systems. When you implement agent memory using memify in Cognee, you convert static knowledge graphs into dynamic, searchable vector indexes that agents can query during runtime.

## What Is Memify in Cognee?

**Memify** serves as the bridge between Cognee’s symbolic knowledge graph and high-performance vector retrieval. Implemented in [`cognee/modules/memify/memify.py`](https://github.com/topoteretes/cognee/blob/main/cognee/modules/memify/memify.py), this pipeline runs a second-stage extraction process that converts graph entities and relationships into embedded triplet data points. Unlike the initial `cognify` step that builds the semantic graph, memify specifically prepares the data for similarity search by indexing content into vector databases such as PGVector or Milvus.

## The Memify Pipeline Architecture

The complete memory implementation follows a four-stage workflow:

- **Data ingestion** – Raw text and documents enter the system via `cognee.add()`.
- **Graph construction** – `cognee.cognify()` extracts entities and relationships to build the foundational knowledge graph.
- **Memory enrichment** – `cognee.memify()` executes `get_triplet_datapoints` to extract (subject, predicate, object) triplets from the graph, then calls `index_data_points` to persist vectors into the configured vector store.
- **Recall** – Agents query the memory using `cognee.search()` with specific `SearchType` parameters to retrieve relevant contextual information.

The default pipeline uses tasks defined in [`cognee/memify_pipelines/memify_default_tasks.py`](https://github.com/topoteretes/cognee/blob/main/cognee/memify_pipelines/memify_default_tasks.py), which configures batch processing with `triplets_batch_size=100` and `batch_size=100` for efficient handling of large graphs.

## Step-by-Step Implementation Guide

### Step 1: Ingest Raw Data

Begin by adding text or documents to a named dataset using `cognee.add()`. This repository supports multiple data formats and automatically handles chunking.

```python
import asyncio
import cognee

async def ingest():
    await cognee.add(
        [
            "We follow PEP8. Add type hints and docstrings.",
            "Releases should not be on Friday. Susan must review PRs.",
        ],
        dataset_name="rules_demo",
    )

if __name__ == "__main__":
    asyncio.run(ingest())

```

### Step 2: Construct the Knowledge Graph

Run `cognee.cognify()` to process the ingested data into a semantic graph. This step identifies entities and their relationships using the default extraction pipeline.

```python
await cognee.cognify(datasets=["rules_demo"])

```

### Step 3: Enrich Memory with Memify

Invoke `cognee.memify()` to transform the graph into searchable vector memory. According to the source code in [`cognee/modules/memify/memify.py`](https://github.com/topoteretes/cognee/blob/main/cognee/modules/memify/memify.py), this function orchestrates the extraction tasks and handles execution either synchronously (default) or asynchronously via `run_in_background=True`.

The pipeline automatically uses `get_default_memify_extraction_tasks` when no custom configuration is provided, extracting graph triplets and indexing them through `index_data_points`.

```python
await cognee.memify(dataset="rules_demo")

```

### Step 4: Query Agent Memory

After enrichment, agents recall information using `cognee.search()`. Specify the `query_type` (such as `SearchType.CODING_RULES`) to target specific memory categories. The underlying vector store returns the most relevant triplets based on embedding similarity.

```python
from cognee.modules.search.types import SearchType

rules = await cognee.search(
    query_type=SearchType.CODING_RULES,
    query_text="List coding rules",
    node_name=["coding_agent_rules"],
)
print("Rules:", rules)

```

### Complete Quickstart Example

Combine all steps into a single implementation:

```python
import asyncio
import cognee
from cognee.modules.search.types import SearchType

async def main():
    # 1️⃣ Add raw text (e.g., coding rules)

    await cognee.add(
        [
            "We follow PEP8. Add type hints and docstrings.",
            "Releases should not be on Friday. Susan must review PRs.",
        ],
        dataset_name="rules_demo",
    )

    # 2️⃣ Build the knowledge graph

    await cognee.cognify(datasets=["rules_demo"])

    # 3️⃣ Enrich the graph → vector memory (default memify pipeline)

    await cognee.memify(dataset="rules_demo")

    # 4️⃣ Query the memory for coding rules

    rules = await cognee.search(
        query_type=SearchType.CODING_RULES,
        query_text="List coding rules",
        node_name=["coding_agent_rules"],
    )
    print("Rules:", rules)

if __name__ == "__main__":
    asyncio.run(main())

```

## Advanced: Session-Based Memory Configuration

For domain-specific requirements like user-session histories, replace the default tasks with session-specific helpers. The `get_session_memify_tasks` function in [`cognee/memify_pipelines/memify_default_tasks.py`](https://github.com/topoteretes/cognee/blob/main/cognee/memify_pipelines/memify_default_tasks.py) provides pre-configured extraction and enrichment tasks designed for conversational memory.

```python
import asyncio
import cognee
from cognee.modules.memify.memify import memify
from cognee.memify_pipelines.memify_default_tasks import get_session_memify_tasks

async def main():
    # Assume a dataset with interaction logs already exists

    await cognee.add("User asked about billing yesterday", dataset_name="session_logs")
    await cognee.cognify(datasets=["session_logs"])

    extraction, enrichment = get_session_memify_tasks()
    await memify(
        extraction_tasks=extraction,
        enrichment_tasks=enrichment,
        dataset="session_logs",
    )
    
    # Now you can search for prior user actions

    result = await cognee.search(
        query_type="semantic",
        query_text="What did the user ask yesterday?",
    )
    print(result)

if __name__ == "__main__":
    asyncio.run(main())

```

## Performance and Configuration Options

The memify pipeline exposes several tuning parameters. Batch processing defaults to 100 triplets per batch (`triplets_batch_size=100`) during extraction and 100 data points during indexing (`batch_size=100`), balancing throughput and memory usage. For large-scale deployments, set `run_in_background=True` when calling `memify()` to execute the pipeline asynchronously without blocking the main agent loop.

## Summary

- **Memify** converts Cognee knowledge graphs into vector-store-backed memory via `cognee.memify()`.
- The pipeline extracts **triplet data points** using `get_triplet_datapoints` and indexes them via `index_data_points` in [`cognee/memify_pipelines/memify_default_tasks.py`](https://github.com/topoteretes/cognee/blob/main/cognee/memify_pipelines/memify_default_tasks.py).
- Default batch sizes are set to **100** for both extraction and indexing operations.
- Agents query enriched memory through `cognee.search()` using specific `SearchType` enumerations.
- Custom memory behaviors can be implemented by passing bespoke extraction and enrichment tasks to the memify function.

## Frequently Asked Questions

### What is the difference between cognify and memify in Cognee?

**Cognify** constructs the initial semantic knowledge graph by extracting entities and relationships from raw data, while **memify** runs a subsequent enrichment pipeline that converts those graph structures into vector embeddings for similarity search. You must run `cognify` before `memify` to ensure the graph exists for triplet extraction.

### Can I run the memify pipeline asynchronously?

Yes. Pass `run_in_background=True` to `cognee.memify()` to execute the enrichment pipeline asynchronously. This prevents blocking your agent’s main execution thread while the system extracts triplets and indexes vectors into the database.

### How do I customize memify for domain-specific agent memory?

You can override the default tasks by importing custom task functions or using helpers like `get_session_memify_tasks` from [`cognee/memify_pipelines/memify_default_tasks.py`](https://github.com/topoteretes/cognee/blob/main/cognee/memify_pipelines/memify_default_tasks.py). Pass your custom extraction and enrichment tasks via the `extraction_tasks` and `enrichment_tasks` parameters in the `memify()` function call.

### Which vector databases does memify support?

Memify supports any vector database configured in your Cognee environment, including **PGVector**, **Milvus**, and other compatible stores. The `index_data_points` task in the memify pipeline handles the specific vector persistence logic based on your configuration settings.