ManagedCode.GraphRag.CosmosDb
0.0.3
Prefix Reserved
See the version list below for details.
dotnet add package ManagedCode.GraphRag.CosmosDb --version 0.0.3
NuGet\Install-Package ManagedCode.GraphRag.CosmosDb -Version 0.0.3
<PackageReference Include="ManagedCode.GraphRag.CosmosDb" Version="0.0.3" />
<PackageVersion Include="ManagedCode.GraphRag.CosmosDb" Version="0.0.3" />
<PackageReference Include="ManagedCode.GraphRag.CosmosDb" />
paket add ManagedCode.GraphRag.CosmosDb --version 0.0.3
#r "nuget: ManagedCode.GraphRag.CosmosDb, 0.0.3"
#:package ManagedCode.GraphRag.CosmosDb@0.0.3
#addin nuget:?package=ManagedCode.GraphRag.CosmosDb&version=0.0.3
#tool nuget:?package=ManagedCode.GraphRag.CosmosDb&version=0.0.3
GraphRAG for .NET
GraphRAG for .NET is a ground-up port of Microsoft’s original GraphRAG Python reference implementation to the modern .NET 9 stack.
Our goal is API parity with the Python pipeline while embracing native .NET idioms (dependency injection, logging abstractions, async I/O, etc.).
The upstream Python code remains available in submodules/graphrag-python for side-by-side reference during the migration.
Repository Structure
graphrag/
├── GraphRag.slnx # Single solution covering every project
├── Directory.Build.props / Directory.Packages.props
├── src/
│ ├── ManagedCode.GraphRag # Core pipeline orchestration & abstractions
│ ├── ManagedCode.GraphRag.CosmosDb # Azure Cosmos DB graph adapter
│ ├── ManagedCode.GraphRag.Neo4j # Neo4j adapter & bolt client integration
│ └── ManagedCode.GraphRag.Postgres # Apache AGE/PostgreSQL graph store adapter
├── tests/
│ └── ManagedCode.GraphRag.Tests
│ ├── Integration/ # Live container-backed scenarios (Testcontainers)
│ └── … unit-level suites
└── submodules/
└── graphrag-python # Original Python implementation (read-only reference)
Key Components
ManagedCode.GraphRag
Hosts the pipelines, workflow execution model, and shared contracts such asIGraphStore,IPipelineCache, etc.ManagedCode.GraphRag.Neo4j / .Postgres / .CosmosDb
Concrete graph-store adapters that satisfy the core abstractions. Each hides the backend-specific SDK plumbing and exposes.AddXGraphStore(...)DI helpers.ManagedCode.GraphRag.Tests
Our only test project.
Unit tests ensure helper APIs behave deterministically.
TheIntegration/folder spins up real infrastructure (Neo4j, Apache AGE/PostgreSQL, optional Cosmos) via Testcontainers—no fakes or mocks.
Prerequisites
| Requirement | Notes |
|---|---|
| .NET SDK 9.0 | The solution targets net9.0; install previews where necessary. |
| Docker Desktop / compatible container runtime | Required for Testcontainers-backed integration tests (Neo4j & Apache AGE/PostgreSQL). |
| (Optional) Azure Cosmos DB Emulator | Set COSMOS_EMULATOR_CONNECTION_STRING to enable Cosmos tests; they are skipped when the env var is absent. |
Getting Started
Clone the repository
git clone https://github.com/<your-org>/graphrag.git cd graphrag git submodule update --init --recursiveRestore & build
dotnet build GraphRag.slnxRepository rule: always build the solution before running tests.
Run the full test suite
dotnet test GraphRag.slnx --logger "console;verbosity=minimal"This command will:
- Restore packages
- Launch Neo4j and Apache AGE/PostgreSQL containers via Testcontainers
- Execute unit + integration tests from
ManagedCode.GraphRag.Tests - Tear down containers automatically when finished
Limit to a specific integration area (optional)
dotnet test tests/ManagedCode.GraphRag.Tests/ManagedCode.GraphRag.Tests.csproj \ --filter "FullyQualifiedName~PostgresGraphStoreIntegrationTests" \ --logger "console;verbosity=normal"
Integration Testing Strategy
- No fakes. We removed the legacy fake Postgres store. Every graph operation in tests uses real services orchestrated by Testcontainers.
- Security coverage.
Integration/PostgresGraphStoreIntegrationTests.csincludes payloads that mimic SQL/Cypher injection attempts to ensure values remain literals and labels/types are strictly validated. - Cross-backend validation.
Integration/GraphStoreIntegrationTests.csexercises Postgres, Neo4j, and Cosmos (when available) through the sharedIGraphStoreabstraction. - Workflow smoke tests. Pipelines (e.g.,
IndexingPipelineRunnerTests) and finalization steps run end-to-end with the fixture-provisioned infrastructure. - Prompt precedence.
Integration/CommunitySummariesIntegrationTests.csproves manual prompt overrides win over auto-tuned assets while still falling back to auto templates when manual text is absent. - Callback and stats instrumentation.
Runtime/PipelineExecutorTests.csnow asserts that pipeline callbacks fire and runtime statistics are captured even when workflows fail early, so custom telemetry remains reliable.
Pipeline Cache
Pipelines exchange state through the IPipelineCache abstraction. Every workflow step receives the same cache instance via PipelineRunContext, so it can reuse expensive results (LLM calls, chunk expansions, graph lookups) that were produced earlier in the run instead of recomputing them. The cache also keeps optional debug payloads per entry so you can persist trace metadata alongside the main value.
To use the built-in in-memory cache, register it alongside the standard ASP.NET Core services:
using GraphRag.Cache;
builder.Services.AddMemoryCache();
builder.Services.AddSingleton<IPipelineCache, MemoryPipelineCache>();
Prefer a different backend? Implement IPipelineCache yourself and register it through DI—the pipeline will pick up your custom cache automatically.
- Per-scope isolation.
MemoryPipelineCache.CreateChild("stage")scopes keys by prefix (parent:stage:key). CallingClearAsyncon the parent removes every nested key, so multi-step workflows do not leak data between stages. - Debug traces. The cache stores optional debug payloads per entry;
DeleteAsyncandClearAsyncalways clear these traces, preventing the diagnostic dictionary from growing unbounded. - Lifecycle guidance. Create the root cache once per pipeline run (the default context factory does this for you) and spawn children inside individual workflows when you need an isolated namespace.
Language Model Registration
GraphRAG delegates language-model configuration to Microsoft.Extensions.AI. Register keyed clients for every ModelId you reference in configuration—pick any string key that matches your config:
using Azure;
using Azure.AI.OpenAI;
using GraphRag.Config;
using Microsoft.Extensions.AI;
var openAi = new OpenAIClient(new Uri(endpoint), new AzureKeyCredential(key));
const string chatModelId = "chat_model";
const string embeddingModelId = "embedding_model";
builder.Services.AddKeyedSingleton<IChatClient>(
chatModelId,
_ => openAi.GetChatClient(chatDeployment));
builder.Services.AddKeyedSingleton<IEmbeddingGenerator<string, Embedding>>(
embeddingModelId,
_ => openAi.GetEmbeddingClient(embeddingDeployment));
Rate limits, retries, and other policies should be configured when you create these clients (for example by wrapping them with Polly handlers). GraphRagConfig.Models simply tracks the set of model keys that have been registered so overrides can validate references.
Indexing, Querying, and Prompt Tuning Alignment
The .NET port mirrors the GraphRAG indexing architecture and its query workflows so downstream applications retain parity with the Python reference implementation.
- Indexing overview. Workflows such as
extract_graph,create_communities, andcommunity_summariesmap 1:1 to the default data flow and persist the same tables (text_units,entities,relationships,communities,community_reports,covariates). The new prompt template loader honours manual or auto-tuned prompts before falling back to the stock templates inprompts/. - Query capabilities. The query pipeline retains global search, local search, drift search, and question generation semantics described in the GraphRAG query overview. Each orchestrator continues to assemble context from the indexed tables so you can reference global or local narratives interchangeably.
- Prompt tuning. GraphRAG’s manual and auto strategies are surfaced through
GraphRagConfig.PromptTuning. Store custom templates underprompts/or pointPromptTuning.Manual.Directory/PromptTuning.Auto.Directoryat your tuning outputs. You can also skip files entirely by assigning inline text (multi-line or prefixed withinline:) to workflow prompt properties. Stage keys and placeholders are documented indocs/indexing-and-query.md.
See docs/indexing-and-query.md for a deeper mapping between the .NET workflows and the research publications underpinning GraphRAG.
Local Cosmos Testing
- Install and start the Azure Cosmos DB Emulator.
- Export the connection string:
export COSMOS_EMULATOR_CONNECTION_STRING="AccountEndpoint=https://localhost:8081/;AccountKey=…;" - Rerun
dotnet test; Cosmos scenarios will seed databases & verify relationships without additional setup.
Development Tips
- Solution layout. Use
GraphRag.slnxin Visual Studio/VS Code/Rider for a complete workspace view. - Formatting / analyzers. Run
dotnet format GraphRag.slnxbefore committing to satisfy the repo analyzers. - Coding conventions.
nullableand implicit usings are enabled; keep annotations accurate.- Async methods should follow the
Asyncsuffix convention. - Prefer DI helpers in
ManagedCode.GraphRagwhen wiring new services.
- Graph adapters. Implement additional backends by conforming to
IGraphStoreand registering viaIServiceCollection.
Contributing
- Fork and clone the repo.
- Create a feature branch from
main. - Follow the repository rules (build before testing; integration tests must use real containers).
- Submit a PR referencing any related issues. Include
dotnet test GraphRag.slnxoutput in the PR body.
See CONTRIBUTING.md for coding standards and PR expectations.
License & Credits
- Licensed under the MIT License.
- Original Python implementation © Microsoft; see the
graphrag-pythonsubmodule for upstream documentation and examples.
Have questions or found a bug? Open an issue or start a discussion—we’re actively evolving the .NET port and welcome feedback. 🚀
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net9.0 is compatible. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net9.0
- ManagedCode.GraphRag (>= 0.0.3)
- Microsoft.Azure.Cosmos (>= 3.54.0)
- Microsoft.Extensions.Logging.Abstractions (>= 9.0.10)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 10.0.7 | 111 | 12/6/2025 |
| 10.0.6 | 640 | 12/3/2025 |
| 10.0.5 | 166 | 11/24/2025 |
| 10.0.4 | 384 | 11/18/2025 |
| 10.0.3 | 215 | 11/16/2025 |
| 10.0.2 | 129 | 11/15/2025 |
| 10.0.1 | 145 | 11/15/2025 |
| 10.0.0 | 235 | 11/14/2025 |
| 0.0.6 | 239 | 11/14/2025 |
| 0.0.5 | 195 | 11/9/2025 |
| 0.0.4 | 149 | 10/31/2025 |
| 0.0.3 | 179 | 10/30/2025 |
| 0.0.2 | 176 | 10/28/2025 |
| 0.0.1 | 171 | 10/27/2025 |