Skip to content

Commit cd10f2f

Browse files
committed
Resolve merge conflict in declarative.md
2 parents fba334e + ac568d7 commit cd10f2f

6 files changed

Lines changed: 385 additions & 15 deletions

File tree

agent-framework/TOC.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,10 @@ items:
178178
href: integrations/purview.md
179179
- name: M365
180180
href: integrations/m365.md
181+
- name: Neo4j GraphRAG Provider
182+
href: integrations/neo4j-graphrag.md
183+
- name: Neo4j Memory Provider
184+
href: integrations/neo4j-memory.md
181185
- name: A2A Protocol
182186
href: integrations/a2a.md
183187
- name: AG-UI Protocol

agent-framework/agents/declarative.md

Lines changed: 43 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,24 +18,53 @@ Declarative agents allow you to define agent configuration using YAML or JSON fi
1818
The following example shows how to create a declarative agent from a YAML configuration:
1919

2020
```csharp
21-
using System;
22-
using System.IO;
2321
using Azure.AI.Projects;
2422
using Azure.Identity;
2523
using Microsoft.Agents.AI;
2624

27-
// Load agent configuration from a YAML file
28-
var yamlContent = File.ReadAllText("agent-config.yaml");
29-
30-
// Create the agent from the YAML definition
31-
AIAgent agent = AgentFactory.CreateFromYaml(
32-
yamlContent,
33-
new AIProjectClient(
34-
new Uri("<your-foundry-project-endpoint>"),
35-
new DefaultAzureCredential()));
36-
37-
// Run the declarative agent
38-
Console.WriteLine(await agent.RunAsync("Why is the sky blue?"));
25+
// Create the chat client
26+
IChatClient chatClient = new AIProjectClient(
27+
new Uri("<your-foundry-project-endpoint>"),
28+
new DefaultAzureCredential())
29+
.GetProjectOpenAIClient()
30+
.GetProjectResponsesClient()
31+
.AsIChatClient("gpt-4o-mini");
32+
33+
// Define the agent using a YAML definition.
34+
var yamlDefinition =
35+
"""
36+
kind: Prompt
37+
name: Assistant
38+
description: Helpful assistant
39+
instructions: You are a helpful assistant. You answer questions in the language specified by the user. You return your answers in a JSON format.
40+
model:
41+
options:
42+
temperature: 0.9
43+
topP: 0.95
44+
outputSchema:
45+
properties:
46+
language:
47+
type: string
48+
required: true
49+
description: The language of the answer.
50+
answer:
51+
type: string
52+
required: true
53+
description: The answer text.
54+
""";
55+
56+
// Create the agent from the YAML definition.
57+
var agentFactory = new ChatClientPromptAgentFactory(chatClient);
58+
var agent = await agentFactory.CreateFromYamlAsync(yamlDefinition);
59+
60+
// Invoke the agent and output the text result.
61+
Console.WriteLine(await agent!.RunAsync("Tell me a joke about a pirate in English."));
62+
63+
// Invoke the agent with streaming support.
64+
await foreach (var update in agent!.RunStreamingAsync("Tell me a joke about a pirate in French."))
65+
{
66+
Console.WriteLine(update);
67+
}
3968
```
4069

4170
> [!WARNING]

agent-framework/agents/rag.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,10 @@ Each connector provides the same `create_search_function` method that can be bri
304304

305305
::: zone-end
306306

307+
## Graph RAG
308+
309+
For GraphRAG using graph traversal enriched search with Cypher queries, see the [Neo4j GraphRAG Provider](../integrations/neo4j-graphrag.md).
310+
307311
## Next steps
308312

309313
> [!div class="nextstepaction"]

agent-framework/integrations/index.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,9 @@ Here is a list of existing providers that can be used.
7070
| Memory AI Context Provider | Release Status |
7171
| ------------------------------------------------------------------ | --------------- |
7272
| [Mem0 Memory Provider](https://github.com/microsoft/agent-framework/blob/main/python/packages/mem0/agent_framework_mem0/_provider.py) | Preview |
73-
| [Redis Provider](https://github.com/microsoft/agent-framework/blob/main/python/packages/redis/agent_framework_redis/_provider.py) | Preview |
73+
| [Neo4j Memory Provider](./neo4j-memory.md) | Preview |
7474
| [Purview Context Provider](./purview.md) | Preview |
75+
| [Redis Provider](https://github.com/microsoft/agent-framework/blob/main/python/packages/redis/agent_framework_redis/_provider.py) | Preview |
7576

7677
::: zone-end
7778

@@ -85,6 +86,7 @@ Here is a list of existing providers that can be used.
8586

8687
| RAG AI Context Provider | Release Status |
8788
| ------------------------------------------------------------------ | --------------- |
89+
| [Neo4j GraphRAG Provider](./neo4j-graphrag.md) | Preview |
8890
| [Text Search Provider](https://github.com/microsoft/agent-framework/blob/main/dotnet/src/Microsoft.Agents.AI/TextSearchProvider.cs) | Preview |
8991

9092
::: zone-end
@@ -94,6 +96,7 @@ Here is a list of existing providers that can be used.
9496
| RAG AI Context Provider | Release Status |
9597
| ------------------------------------------------------------------ | --------------- |
9698
| [Azure AI Search Provider](https://github.com/microsoft/agent-framework/blob/main/python/packages/azure-ai-search/agent_framework_azure_ai_search/_search_provider.py) | Preview |
99+
| [Neo4j GraphRAG Provider](./neo4j-graphrag.md) | Preview |
97100

98101
::: zone-end
99102

Lines changed: 202 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,202 @@
1+
---
2+
title: Neo4j GraphRAG Context Provider for Agent Framework
3+
description: Learn how to use the Neo4j GraphRAG Context Provider to add knowledge graph retrieval capabilities to your Agent Framework agents
4+
zone_pivot_groups: programming-languages
5+
author: retroryan
6+
ms.topic: article
7+
ms.author: westey
8+
ms.date: 03/29/2026
9+
ms.service: agent-framework
10+
---
11+
12+
# Neo4j GraphRAG Context Provider
13+
14+
The Neo4j GraphRAG Context Provider adds Retrieval Augmented Generation (RAG) capabilities to Agent Framework agents using a Neo4j knowledge graph. It supports vector, fulltext, and hybrid search modes, with optional graph traversal to enrich results with related entities via custom Cypher queries.
15+
16+
For knowledge graph scenarios where relationships between entities matter, this provider retrieves relevant subgraphs rather than isolated text chunks, giving agents richer context for generating responses.
17+
18+
## Why use Neo4j for GraphRAG?
19+
20+
- **Graph enhanced retrieval**: Standard vector search returns isolated chunks; graph traversal follows connections to surface related entities, giving agents richer context.
21+
- **Flexible search modes**: Combine vector similarity, keyword/BM25, and graph traversal in a single query.
22+
- **Custom retrieval queries**: Cypher queries let you control exactly which relationships to traverse and what context to return.
23+
24+
> [!NOTE]
25+
> Neo4j offers two separate integrations for Agent Framework. This provider 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](./neo4j-memory.md).
26+
27+
::: zone pivot="programming-language-csharp"
28+
29+
## Prerequisites
30+
31+
- A Neo4j instance (self-hosted or [Neo4j AuraDB](https://neo4j.com/cloud/aura/)) with a vector or fulltext index configured
32+
- An Azure AI Foundry project with a deployed chat model and an embedding model (e.g. `text-embedding-3-small`)
33+
- Environment variables set: `NEO4J_URI`, `NEO4J_USERNAME`, `NEO4J_PASSWORD`, `AZURE_AI_SERVICES_ENDPOINT`, `AZURE_AI_EMBEDDING_NAME`
34+
- Azure CLI credentials configured (`az login`)
35+
- .NET 8.0 or later
36+
37+
## Installation
38+
39+
```bash
40+
dotnet add package Neo4j.AgentFramework.GraphRAG
41+
```
42+
43+
## Usage
44+
45+
```csharp
46+
using Azure.AI.OpenAI;
47+
using Azure.Identity;
48+
using Microsoft.Agents.AI;
49+
using Microsoft.Agents.AI.OpenAI;
50+
using Microsoft.Extensions.AI;
51+
using Neo4j.AgentFramework.GraphRAG;
52+
using Neo4j.Driver;
53+
54+
// Read connection details from environment variables
55+
var neo4jSettings = new Neo4jSettings();
56+
var azureEndpoint = Environment.GetEnvironmentVariable("AZURE_AI_SERVICES_ENDPOINT")!;
57+
58+
// Create embedding generator
59+
var credential = new DefaultAzureCredential();
60+
var azureClient = new AzureOpenAIClient(new Uri(azureEndpoint), credential);
61+
62+
IEmbeddingGenerator<string, Embedding<float>> embedder = azureClient
63+
.GetEmbeddingClient("text-embedding-3-small")
64+
.AsIEmbeddingGenerator();
65+
66+
// Create Neo4j driver
67+
await using var driver = GraphDatabase.Driver(
68+
neo4jSettings.Uri, AuthTokens.Basic(neo4jSettings.Username, neo4jSettings.Password!));
69+
70+
// Create the Neo4j context provider
71+
await using var provider = new Neo4jContextProvider(driver, new Neo4jContextProviderOptions
72+
{
73+
IndexName = "chunkEmbeddings",
74+
IndexType = IndexType.Vector,
75+
EmbeddingGenerator = embedder,
76+
TopK = 5,
77+
RetrievalQuery = """
78+
MATCH (node)-[:FROM_DOCUMENT]->(doc:Document)
79+
OPTIONAL MATCH (doc)<-[:FILED]-(company:Company)
80+
RETURN node.text AS text, score, doc.title AS title, company.name AS company
81+
ORDER BY score DESC
82+
""",
83+
});
84+
85+
// Create an agent with the provider
86+
AIAgent agent = azureClient
87+
.GetChatClient("gpt-4o")
88+
.AsIChatClient()
89+
.AsBuilder()
90+
.UseAIContextProviders(provider)
91+
.BuildAIAgent(new ChatClientAgentOptions
92+
{
93+
ChatOptions = new ChatOptions
94+
{
95+
Instructions = "You are a financial analyst assistant.",
96+
},
97+
});
98+
99+
var session = await agent.CreateSessionAsync();
100+
Console.WriteLine(await agent.RunAsync("What risks does Acme Corp face?", session));
101+
```
102+
103+
## Key features
104+
105+
- **Index-driven**: Works with any Neo4j vector or fulltext index
106+
- **Graph traversal**: Custom Cypher queries enrich search results with related entities
107+
- **Search modes**: Vector (semantic similarity), fulltext (keyword/BM25), or hybrid (both combined)
108+
109+
## Resources
110+
111+
- [Neo4j Context Provider repository](https://github.com/neo4j-labs/neo4j-maf-provider)
112+
- [NuGet package page](https://www.nuget.org/packages/Neo4j.AgentFramework.GraphRAG)
113+
- [Workshop: Neo4j Context Providers for Agent Framework](https://github.com/neo4j-partners/maf-context-providers-lab)
114+
115+
::: zone-end
116+
117+
::: zone pivot="programming-language-python"
118+
119+
## Prerequisites
120+
121+
- A Neo4j instance (self-hosted or [Neo4j AuraDB](https://neo4j.com/cloud/aura/)) with a vector or fulltext index configured
122+
- An Azure AI Foundry project with a deployed chat model and an embedding model (e.g. `text-embedding-ada-002`)
123+
- Environment variables set: `NEO4J_URI`, `NEO4J_USERNAME`, `NEO4J_PASSWORD`, `AZURE_AI_PROJECT_ENDPOINT`, `AZURE_AI_EMBEDDING_NAME`
124+
- Azure CLI credentials configured (`az login`)
125+
- Python 3.10 or later
126+
127+
## Installation
128+
129+
```bash
130+
pip install agent-framework-neo4j
131+
```
132+
133+
## Usage
134+
135+
```python
136+
from agent_framework import Agent
137+
from agent_framework.azure import AzureAIClient
138+
from agent_framework_neo4j import Neo4jContextProvider, Neo4jSettings, AzureAISettings, AzureAIEmbedder
139+
from azure.identity import DefaultAzureCredential
140+
from azure.identity.aio import AzureCliCredential
141+
142+
# Reads NEO4J_URI, NEO4J_USERNAME, NEO4J_PASSWORD from environment variables
143+
neo4j_settings = Neo4jSettings()
144+
145+
# Reads AZURE_AI_PROJECT_ENDPOINT, AZURE_AI_EMBEDDING_NAME from environment variables
146+
azure_settings = AzureAISettings()
147+
148+
sync_credential = DefaultAzureCredential()
149+
embedder = AzureAIEmbedder(
150+
endpoint=azure_settings.inference_endpoint,
151+
credential=sync_credential,
152+
model=azure_settings.embedding_model,
153+
)
154+
155+
neo4j_provider = Neo4jContextProvider(
156+
uri=neo4j_settings.uri,
157+
username=neo4j_settings.username,
158+
password=neo4j_settings.get_password(),
159+
index_name=neo4j_settings.vector_index_name,
160+
index_type="vector",
161+
embedder=embedder,
162+
top_k=5,
163+
retrieval_query="""
164+
MATCH (node)-[:FROM_DOCUMENT]->(doc:Document)
165+
OPTIONAL MATCH (doc)<-[:FILED]-(company:Company)
166+
RETURN node.text AS text, score, doc.title AS title, company.name AS company
167+
ORDER BY score DESC
168+
""",
169+
)
170+
171+
async with (
172+
neo4j_provider,
173+
AzureCliCredential() as credential,
174+
AzureAIClient(credential=credential, project_endpoint=azure_settings.project_endpoint) as client,
175+
Agent(
176+
client=client,
177+
instructions="You are a financial analyst assistant.",
178+
context_providers=[neo4j_provider],
179+
) as agent,
180+
):
181+
session = agent.create_session()
182+
response = await agent.run("What risks does Acme Corp face?", session=session)
183+
```
184+
185+
## Key features
186+
187+
- **Index-driven**: Works with any Neo4j vector or fulltext index
188+
- **Graph traversal**: Custom Cypher queries enrich search results with related entities
189+
- **Search modes**: Vector (semantic similarity), fulltext (keyword/BM25), or hybrid (both combined)
190+
191+
## Resources
192+
193+
- [Neo4j Context Provider repository](https://github.com/neo4j-labs/neo4j-maf-provider)
194+
- [PyPI package page](https://pypi.org/project/agent-framework-neo4j/)
195+
- [Workshop: Neo4j Context Providers for Agent Framework](https://github.com/neo4j-partners/maf-context-providers-lab)
196+
197+
::: zone-end
198+
199+
## Next steps
200+
201+
> [!div class="nextstepaction"]
202+
> [Neo4j Memory Provider](./neo4j-memory.md)

0 commit comments

Comments
 (0)