Skip to content

.NET: Add Cosmos NoSQL vector memory sample - #7552

Open
Saurish (nos-redacted) wants to merge 5 commits into
microsoft:mainfrom
nos-redacted:rank4-cosmos-nosql-memory-sample
Open

.NET: Add Cosmos NoSQL vector memory sample#7552
Saurish (nos-redacted) wants to merge 5 commits into
microsoft:mainfrom
nos-redacted:rank4-cosmos-nosql-memory-sample

Conversation

@nos-redacted

@nos-redacted Saurish (nos-redacted) commented Aug 7, 2026

Copy link
Copy Markdown

Motivation & Context

The .NET AgentWithMemory samples demonstrate progressively richer memory providers, but they do not show how to use Azure Cosmos DB for NoSQL as a persistent vector store. This adds an Azure-first reference for semantic chat-history recall across independent agent sessions while reusing the existing ChatHistoryMemoryProvider and VectorStore abstractions.

Description & Review Guide

  • What are the major changes?
    • Adds Step 08, which configures CosmosNoSqlVectorStore with a Microsoft Foundry embedding deployment and passes it to ChatHistoryMemoryProvider.
    • Uses a session-specific storage scope and a user-wide search scope, then runs two separate AgentSession instances to demonstrate cross-session recall.
    • Configures the Cosmos client for System.Text.Json, creates the configured database when absent, and lets the connector create the vector-enabled collection.
    • Registers the sample in the parent index, solution, and automated sample verifier.
    • Adds the CommunityToolkit Cosmos NoSQL connector and raises the central Microsoft.Azure.Cosmos version from 3.54.0 to 3.61.0, which is required by connector 1.0.0.
  • What is the impact of these changes?
    • This is an additive sample and does not change Agent Framework public APIs.
    • Focused sample and verifier builds, format verification, solution registration, and the existing Cosmos unit-test slice pass. The verifier discovers the new sample and skips cleanly when its required endpoints are unset.
    • A live Foundry/Cosmos run was not performed because those service endpoints are not configured. The full solution build reached unrelated GitHub Copilot samples that could not download a CLI archive from public npm because of the managed network's TLS restrictions.
  • What do you want reviewers to focus on?
    • The Cosmos client serializer configuration, the storage/search scope choices, and the central Cosmos SDK version bump required by the connector.

Related Issue

Fixes #7551

Contribution Checklist

  • The code builds clean without any errors or warnings
  • All unit tests pass, and I have added new tests where possible
  • The PR follows the Contribution Guidelines
  • This PR is linked to an issue and there is no other open PR for this issue (see Related Issue above).
  • This is not a breaking change. If it is a breaking change, add the breaking change label (or add "[BREAKING]" to the title prefix, before or after any language prefix) — a workflow keeps the label and title prefix in sync automatically.

Copilot AI lite review requested due to automatic review settings August 7, 2026 00:09
@agent-framework-automation agent-framework-automation Bot added documentation Usage: [Issues, PRs], Target: documentation in the code base and learn docs .NET Usage: [Issues, PRs], Target: .Net labels Aug 7, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Warning

Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.

Adds a new .NET “AgentWithMemory” sample demonstrating persistent, cross-session chat history recall backed by Azure Cosmos DB for NoSQL vector search.

Changes:

  • Introduces Step 08 sample using CosmosNoSqlVectorStore + ChatHistoryMemoryProvider to persist and recall chat history across AgentSessions.
  • Registers the sample in the parent README, solution, and sample verifier.
  • Updates central package versions to include the CommunityToolkit Cosmos NoSQL vector connector and bumps Microsoft.Azure.Cosmos.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
dotnet/samples/02-agents/AgentWithMemory/README.md Adds Step 08 link to the sample index.
dotnet/samples/02-agents/AgentWithMemory/AgentWithMemory_Step08_MemoryUsingCosmosNoSql/README.md Documents prerequisites, env vars, and behavior for the new sample.
dotnet/samples/02-agents/AgentWithMemory/AgentWithMemory_Step08_MemoryUsingCosmosNoSql/Program.cs Implements the Cosmos NoSQL vector-store-backed memory sample and cross-session recall.
dotnet/samples/02-agents/AgentWithMemory/AgentWithMemory_Step08_MemoryUsingCosmosNoSql/AgentWithMemory_Step08_MemoryUsingCosmosNoSql.csproj Adds the new sample project and dependencies.
dotnet/eng/verify-samples/AgentsSamples.cs Registers the new sample with the verifier and required env vars.
dotnet/agent-framework-dotnet.slnx Adds the sample project to the solution.
dotnet/Directory.Packages.props Adds CommunityToolkit Cosmos NoSQL connector version and bumps Microsoft.Azure.Cosmos.

@nos-redacted

Saurish (nos-redacted) commented Aug 7, 2026

Copy link
Copy Markdown
Author

Follow-up commit 862b907 addresses all four Copilot comments: embedding dimensions are configurable and validated, sample memory is isolated with a per-run user scope, and the unused direct Newtonsoft.Json reference is removed. The affected sample builds successfully with dotnet build --no-restore, editor diagnostics are clean, git diff --check passes, and all review threads are resolved. The PR is now ready for review; the contributor license check is currently queued. westey (@westey-m), could you review this AgentWithMemory sample when available?

@nos-redacted

Copy link
Copy Markdown
Author

@microsoft-github-policy-service agree company="Microsoft"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Usage: [Issues, PRs], Target: documentation in the code base and learn docs .NET Usage: [Issues, PRs], Target: .Net

Projects

None yet

Development

Successfully merging this pull request may close these issues.

.NET: [Sample Request] Add Cosmos NoSQL vector memory sample

3 participants