Skip to content

Commit 2f41998

Browse files
committed
Python: Adds sample documentation for two separate Neo4j context providers for retrieval and memory
1 parent 56dbe96 commit 2f41998

7 files changed

Lines changed: 135 additions & 31 deletions

File tree

agent-framework/user-guide/agents/TOC.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
href: agent-memory.md
99
- name: Agent Tools
1010
href: agent-tools.md
11-
- name: Agent Retrieval Augmented Generation (RAG)
12-
href: agent-rag.md
11+
- name: Agent GraphRAG
12+
href: agent-graphrag.md
1313
- name: Agent Middleware
1414
href: agent-middleware.md
1515
- name: Agent Background Responses

agent-framework/user-guide/agents/agent-rag.md renamed to agent-framework/user-guide/agents/agent-graphrag.md

Lines changed: 59 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
2-
title: Agent Retrieval Augmented Generation (RAG)
3-
description: Learn how to use Retrieval Augmented Generation (RAG) with Agent Framework
2+
title: Agent GraphRAG
3+
description: Learn how to use GraphRAG with Agent Framework
44
zone_pivot_groups: programming-languages
55
author: westey-m
66
ms.topic: reference
@@ -9,17 +9,17 @@ ms.date: 11/11/2025
99
ms.service: agent-framework
1010
---
1111

12-
# Agent Retrieval Augmented Generation (RAG)
12+
# Agent GraphRAG
1313

14-
Microsoft Agent Framework supports adding Retrieval Augmented Generation (RAG) capabilities to agents easily by adding AI Context Providers to the agent.
14+
Microsoft Agent Framework supports adding GraphRAG capabilities to agents easily by adding AI Context Providers to the agent.
1515

1616
::: zone pivot="programming-language-csharp"
1717

1818
## Using TextSearchProvider
1919

20-
The `TextSearchProvider` class is an out-of-the-box implementation of a RAG context provider.
20+
The `TextSearchProvider` class is an out-of-the-box implementation of a GraphRAG context provider.
2121

22-
It can easily be attached to a `ChatClientAgent` using the `AIContextProviderFactory` option to provide RAG capabilities to the agent.
22+
It can easily be attached to a `ChatClientAgent` using the `AIContextProviderFactory` option to provide GraphRAG capabilities to the agent.
2323

2424
The factory is an async function that receives a context object and a cancellation token.
2525

@@ -92,7 +92,7 @@ The `TextSearchProvider` class supports the following options via the `TextSearc
9292

9393
## Using Semantic Kernel VectorStore with Agent Framework
9494

95-
Agent Framework supports using Semantic Kernel's VectorStore collections to provide RAG capabilities to agents. This is achieved through the bridge functionality that converts Semantic Kernel search functions into Agent Framework tools.
95+
Agent Framework supports using Semantic Kernel's VectorStore collections to provide GraphRAG capabilities to agents. This is achieved through the bridge functionality that converts Semantic Kernel search functions into Agent Framework tools.
9696

9797
> [!IMPORTANT]
9898
> This feature requires `semantic-kernel` version 1.38 or higher.
@@ -160,7 +160,7 @@ async with collection:
160160
tools=search_tool
161161
)
162162

163-
# Use the agent with RAG capabilities
163+
# Use the agent with GraphRAG capabilities
164164
response = await agent.run("How do I return a product?")
165165
print(response.text)
166166
```
@@ -295,6 +295,57 @@ This pattern works with any Semantic Kernel VectorStore connector, including:
295295

296296
Each connector provides the same `create_search_function` method that can be bridged to Agent Framework tools, allowing you to choose the vector database that best fits your needs. See [the full list here](/semantic-kernel/concepts/vector-store-connectors/out-of-the-box-connectors).
297297

298+
### Using Neo4j for GraphRAG
299+
300+
Neo4j offers two separate integrations for Agent Framework, each serving a different purpose. This provider (`agent-framework-neo4j`) is for **GraphRAG** — searching an existing knowledge graph to ground agent responses. For **persistent memory** that learns from conversations and builds a knowledge graph over time, see the [Neo4j Memory Provider](./agent-memory.md#neo4j-memory-provider).
301+
302+
For knowledge graph scenarios where relationships between entities matter, the Neo4j Context Provider offers GraphRAG. It supports vector, fulltext, and hybrid search modes, with optional graph traversal to enrich results with related entities via custom Cypher queries.
303+
304+
```python
305+
from agent_framework import Agent
306+
from agent_framework.azure import AzureAIClient
307+
from agent_framework_neo4j import Neo4jContextProvider, Neo4jSettings, AzureAIEmbedder
308+
from azure.identity.aio import AzureCliCredential
309+
310+
settings = Neo4jSettings()
311+
312+
neo4j_provider = Neo4jContextProvider(
313+
uri=settings.uri,
314+
username=settings.username,
315+
password=settings.get_password(),
316+
index_name="documentChunks",
317+
index_type="vector",
318+
embedder=AzureAIEmbedder(...),
319+
top_k=5,
320+
retrieval_query="""
321+
MATCH (node)-[:FROM_DOCUMENT]->(doc:Document)
322+
OPTIONAL MATCH (doc)<-[:FILED]-(company:Company)
323+
RETURN node.text AS text, score, doc.title AS title, company.name AS company
324+
ORDER BY score DESC
325+
""",
326+
)
327+
328+
async with (
329+
neo4j_provider,
330+
AzureAIClient(credential=AzureCliCredential(), project_endpoint=project_endpoint) as client,
331+
Agent(
332+
client=client,
333+
instructions="You are a financial analyst assistant.",
334+
context_providers=[neo4j_provider],
335+
) as agent,
336+
):
337+
session = agent.create_session()
338+
response = await agent.run("What risks does Acme Corp face?", session=session)
339+
```
340+
341+
Key features:
342+
- **Index-driven**: Works with any Neo4j vector or fulltext index
343+
- **Graph traversal**: Custom Cypher queries enrich search results with related entities
344+
- **Search modes**: Vector (semantic similarity), fulltext (keyword/BM25), or hybrid (both combined)
345+
346+
> [!TIP]
347+
> Install with `pip install agent-framework-neo4j`. See the [Neo4j Context Provider repository](https://github.com/neo4j-labs/neo4j-maf-provider) for complete documentation.
348+
298349
::: zone-end
299350

300351
## Next steps

agent-framework/user-guide/agents/agent-memory.md

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,59 @@ agent = ChatAgent(
329329
)
330330
```
331331

332+
#### Neo4j Memory Provider
333+
334+
Neo4j offers two separate integrations for Agent Framework, each serving a different purpose. This provider (`neo4j-agent-memory`) is for **persistent memory** — storing and recalling agent interactions, extracting entities, and building a knowledge graph over time. For **GraphRAG** from an existing knowledge graph using vector, fulltext, or hybrid search, see the [Neo4j Context Provider for GraphRAG](./agent-graphrag.md#using-neo4j-for-graphrag).
335+
336+
The Neo4j Memory Provider gives agents persistent memory backed by a knowledge graph. Unlike GraphRAG providers that retrieve from static knowledge bases, the memory provider stores and recalls agent interactions, automatically extracting entities and building a knowledge graph over time.
337+
338+
The provider manages three types of memory:
339+
- **Short-term memory**: Conversation history and recent context
340+
- **Long-term memory**: Entities, preferences, and facts extracted from interactions
341+
- **Reasoning memory**: Past reasoning traces and tool usage patterns
342+
343+
```python
344+
from agent_framework import Agent
345+
from agent_framework.azure import AzureAIClient
346+
from azure.identity.aio import AzureCliCredential
347+
from neo4j_agent_memory import MemoryClient, MemorySettings
348+
from neo4j_agent_memory.integrations.microsoft_agent import (
349+
Neo4jMicrosoftMemory,
350+
create_memory_tools,
351+
)
352+
353+
settings = MemorySettings()
354+
memory_client = MemoryClient(settings)
355+
356+
async with memory_client:
357+
memory = Neo4jMicrosoftMemory.from_memory_client(
358+
memory_client=memory_client,
359+
session_id="user-123",
360+
)
361+
tools = create_memory_tools(memory)
362+
363+
async with (
364+
AzureAIClient(credential=AzureCliCredential(), project_endpoint=project_endpoint) as client,
365+
Agent(
366+
client=client,
367+
instructions="You are a helpful assistant with persistent memory.",
368+
tools=tools,
369+
context_providers=[memory.context_provider],
370+
) as agent,
371+
):
372+
session = agent.create_session()
373+
response = await agent.run("Remember that I prefer window seats on flights.", session=session)
374+
```
375+
376+
Key features:
377+
- **Bidirectional**: Automatically retrieves relevant context before invocation and saves new memories after responses
378+
- **Entity extraction**: Builds a knowledge graph from conversations using a multi-stage extraction pipeline
379+
- **Preference learning**: Infers and stores user preferences across sessions
380+
- **Memory tools**: Agents can explicitly search memory, remember preferences, and find entity connections
381+
382+
> [!TIP]
383+
> Install with `pip install neo4j-agent-memory[microsoft-agent]`. See the [Neo4j Agent Memory repository](https://github.com/neo4j-labs/agent-memory) for complete documentation.
384+
332385
### Thread Serialization and Persistence
333386
The framework supports serializing entire thread states for persistence across application restarts:
334387

agent-framework/user-guide/agents/agent-tools.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,4 +292,4 @@ result = await agent.run(
292292
## Next steps
293293

294294
> [!div class="nextstepaction"]
295-
> [Agent Retrieval Augmented Generation](./agent-rag.md)
295+
> [Agent GraphRAG](./agent-graphrag.md)

semantic-kernel/Frameworks/agent/TOC.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
href: agent-streaming.md
1515
- name: Agent Memory
1616
href: agent-memory.md
17-
- name: Agent Text Search (RAG)
18-
href: agent-rag.md
17+
- name: Agent GraphRAG
18+
href: agent-graphrag.md
1919
- name: Supported Agent Types
2020
href: agent-types/TOC.yml
2121
- name: Agent Orchestration

semantic-kernel/Frameworks/agent/agent-rag.md renamed to semantic-kernel/Frameworks/agent/agent-graphrag.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
2-
title: Adding Retrieval Augmented Generation (RAG) to Semantic Kernel Agents
3-
description: How to use the TextSearchProvider for Retrieval Augmented Generation (RAG) with Semantic Kernel Agents
2+
title: Adding GraphRAG to Semantic Kernel Agents
3+
description: How to use the TextSearchProvider for GraphRAG with Semantic Kernel Agents
44
zone_pivot_groups: programming-languages
55
author: westey-m
66
ms.topic: conceptual
@@ -9,14 +9,14 @@ ms.date: 05/22/2025
99
ms.service: semantic-kernel
1010
---
1111

12-
# Adding Retrieval Augmented Generation (RAG) to Semantic Kernel Agents
12+
# Adding GraphRAG to Semantic Kernel Agents
1313

1414
::: zone pivot="programming-language-csharp"
1515

1616
> [!WARNING]
17-
> The Semantic Kernel Agent RAG functionality is experimental, subject to change, and will only be finalized based on feedback and evaluation.
17+
> The Semantic Kernel Agent GraphRAG functionality is experimental, subject to change, and will only be finalized based on feedback and evaluation.
1818
19-
## Using the TextSearchProvider for RAG
19+
## Using the TextSearchProvider for GraphRAG
2020

2121
The `Microsoft.SemanticKernel.Data.TextSearchProvider` allows agents to retrieve relevant documents based on user input and inject them into the agent's context for more informed responses.
2222
It integrates an `Microsoft.SemanticKernel.Data.ITextSearch` instance with Semantic Kernel agents.
@@ -30,7 +30,7 @@ We also provide a `Microsoft.SemanticKernel.Data.TextSearchStore`, which provide
3030

3131
The `TextSearchProvider` can be used with a `VectorStore` and `TextSearchStore` to store and search text documents.
3232

33-
The following example demonstrates how to set up and use the `TextSearchProvider` with a `TextSearchStore` and `InMemoryVectorStore` for an agent to perform simple RAG over text.
33+
The following example demonstrates how to set up and use the `TextSearchProvider` with a `TextSearchStore` and `InMemoryVectorStore` for an agent to perform simple GraphRAG over text.
3434

3535
```csharp
3636
// Create an embedding generator using Azure OpenAI.
@@ -58,7 +58,7 @@ ChatCompletionAgent agent = new()
5858
Name = "FriendlyAssistant",
5959
Instructions = "You are a friendly assistant",
6060
Kernel = kernel,
61-
// This setting must be set to true when using the on-demand RAG feature
61+
// This setting must be set to true when using the on-demand GraphRAG feature
6262
UseImmutableKernel = true
6363
};
6464

@@ -67,7 +67,7 @@ ChatHistoryAgentThread agentThread = new();
6767
var textSearchProvider = new TextSearchProvider(textSearchStore);
6868
agentThread.AIContextProviders.Add(textSearchProvider);
6969

70-
// Use the agent with RAG capabilities.
70+
// Use the agent with GraphRAG capabilities.
7171
ChatMessageContent response = await agent.InvokeAsync("Where is Contoso based?", agentThread).FirstAsync();
7272
Console.WriteLine(response.Content);
7373
```
@@ -110,7 +110,7 @@ using var textSearchStore = new TextSearchStore<string>(
110110
);
111111
```
112112

113-
### Automatic vs on-demand RAG
113+
### Automatic vs on-demand GraphRAG
114114

115115
The `TextSearchProvider` can perform searches automatically during each agent invocation or allow on-demand searches via tool calls when the agent needs additional information.
116116

@@ -182,7 +182,7 @@ You can write your own output by implementing and providing this callback.
182182

183183
**Note**: If this delegate is provided, the `ContextPrompt` and `IncludeCitationsPrompt` settings will not be used.
184184

185-
## Combining RAG with Other Providers
185+
## Combining GraphRAG with Other Providers
186186

187187
The `TextSearchProvider` can be combined with other providers, such as `mem0` or `WhiteboardProvider`, to create agents with both memory and retrieval capabilities.
188188

@@ -201,7 +201,7 @@ By combining these features, agents can deliver a more personalized and context-
201201
## Next steps
202202

203203
> [!div class="nextstepaction"]
204-
> [Explore the Agent with RAG sample](https://github.com/microsoft/semantic-kernel/blob/main/dotnet/samples/Concepts/Agents/ChatCompletion_Rag.cs)
204+
> [Explore the Agent with GraphRAG sample](https://github.com/microsoft/semantic-kernel/blob/main/dotnet/samples/Concepts/Agents/ChatCompletion_Rag.cs)
205205
206206
::: zone-end
207207

semantic-kernel/concepts/vector-store-connectors/index.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,18 +42,18 @@ The Semantic Kernel provided imlementations are referred to as 'connectors'.
4242

4343
::: zone pivot="programming-language-csharp"
4444

45-
## Retrieval Augmented Generation (RAG) with Vector Stores
45+
## GraphRAG with Vector Stores
4646

4747
The vector store abstraction is a low level api for adding and retrieving data from vector stores.
48-
Semantic Kernel has built-in support for using any one of the Vector Store implementations for RAG.
48+
Semantic Kernel has built-in support for using any one of the Vector Store implementations for GraphRAG.
4949
This is achieved by wrapping `IVectorSearchable<TRecord>` and exposing it as a Text Search implementation.
5050

5151
> [!TIP]
52-
> To learn more about how to use vector stores for RAG see [How to use Vector Stores with Semantic Kernel Text Search](../text-search/text-search-vector-stores.md).
52+
> To learn more about how to use vector stores for GraphRAG see [How to use Vector Stores with Semantic Kernel Text Search](../text-search/text-search-vector-stores.md).
5353
> [!TIP]
5454
> To learn more about text search see [What is Semantic Kernel Text Search?](../text-search/index.md)
5555
> [!TIP]
56-
> To learn more about how to quickly add RAG into your agent see [Adding Retrieval Augmented Generation (RAG) to Semantic Kernel Agents](../../Frameworks/agent/agent-rag.md).
56+
> To learn more about how to quickly add GraphRAG into your agent see [Adding GraphRAG to Semantic Kernel Agents](../../Frameworks/agent/agent-graphrag.md).
5757
5858
## The Vector Store Abstraction
5959

@@ -81,14 +81,14 @@ Finally, the abstract base class inherits from `IVectorSearchable<TRecord>` prov
8181
::: zone-end
8282
::: zone pivot="programming-language-python"
8383

84-
## Retrieval Augmented Generation (RAG) with Vector Stores
84+
## GraphRAG with Vector Stores
8585

8686
The vector store abstractions are a low level api for adding and retrieving data from vector stores.
87-
Semantic Kernel has built-in support for using any one of the Vector Store implementations for RAG.
87+
Semantic Kernel has built-in support for using any one of the Vector Store implementations for GraphRAG.
8888
This is achieved by wrapping `VectorSearchBase[TKey, TModel]` with either `VectorizedSearchMixin[Tmodel]`, `VectorizableTextSearchMixin[TModel]` or `VectorTextSearch[TModel]` and exposing it as a Text Search implementation.
8989

9090
> [!TIP]
91-
> To learn more about how to use vector stores for RAG see [How to use Vector Stores with Semantic Kernel Text Search](../text-search/text-search-vector-stores.md).
91+
> To learn more about how to use vector stores for GraphRAG see [How to use Vector Stores with Semantic Kernel Text Search](../text-search/text-search-vector-stores.md).
9292
> [!TIP]
9393
> To learn more about text search see [What is Semantic Kernel Text Search?](../text-search/index.md)
9494

0 commit comments

Comments
 (0)