# AzureAIMemoryRetriever

> **Class** in `langchain_azure_ai`

📖 [View in docs](https://reference.langchain.com/python/langchain-azure-ai/retrievers/azure_ai_memory_retriever/AzureAIMemoryRetriever)

LangChain retriever that queries Foundry Memory with multi-turn context.

This retriever is designed for close coupling with
`AzureAIMemoryChatMessageHistory`. When bound to a history instance via
`history_ref`, it provides incremental search capabilities with multi-turn
conversation context. Use standalone mode only for one-off queries without
conversation context.

This retriever queries Azure AI Foundry Memory, supporting both standalone
retrieval and history-bound incremental search with `previous_search_id`.

**Examples**

Standalone retriever (one-off search without context):

```python
from azure.identity import DefaultAzureCredential

retriever = AzureAIMemoryRetriever(
    project_endpoint="https://myproject.api.azureml.ms",
    credential=DefaultAzureCredential(),
    store_name="my_store",
    scope="user:123",
    k=5,
)
docs = retriever.invoke("What are my coffee preferences?")
```

With endpoint from environment variable:

```python
retriever = AzureAIMemoryRetriever(
    store_name="my_store",
    scope="user:123",
    k=5,
)
docs = retriever.invoke("What are my preferences?")
```

History-bound retriever (recommended):

```python
from langchain_core.chat_history import InMemoryChatMessageHistory
from langchain_azure_ai.chat_history import (
    AzureAIMemoryChatMessageHistory,
)

history = AzureAIMemoryChatMessageHistory(
    project_endpoint="https://myproject.api.azureml.ms",
    store_name="my_store",
    scope="user:123",
    base_history=InMemoryChatMessageHistory(),
)
retriever = history.get_retriever(k=5)
docs = retriever.invoke("Tell me more")
```

## Signature

```python
AzureAIMemoryRetriever()
```

## Extends

- `BaseRetriever`

## Properties

- `store_name`
- `scope`
- `session_id`
- `k`
- `project_endpoint`
- `credential`
- `history_ref`
- `model_config`

---

[View source on GitHub](https://github.com/langchain-ai/langchain-azure/blob/7a6a664d617264df8dcb12fcfb1bacc09f21d504/libs/azure-ai/langchain_azure_ai/retrievers/azure_ai_memory_retriever.py#L79)