Skip to content

Reimplement ToolDescriptionEvaluator VectorDB on Microsoft.Extensions.VectorData#3057

Open
vcolin7 with Copilot wants to merge 8 commits into
mainfrom
copilot/make-vectordb-implementation
Open

Reimplement ToolDescriptionEvaluator VectorDB on Microsoft.Extensions.VectorData#3057
vcolin7 with Copilot wants to merge 8 commits into
mainfrom
copilot/make-vectordb-implementation

Conversation

Copilot AI commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

The ToolDescriptionEvaluator's VectorDB was a bespoke in-memory store with a custom API. Building it on the Microsoft.Extensions.VectorData abstractions lets it be swapped for another provider with minimal consumer changes and unblocks future use of Microsoft.Extensions.DataIngestion for chunking and processing.

Changes

  • Vector data abstractions: Derived VectorDB from VectorStore and added InMemoryVectorStoreCollection : VectorStoreCollection<string, Entry>. The existing brute-force cosine-similarity search, sorted-key storage, and parallel divide-and-conquer query path are preserved behind the standard UpsertAsync, SearchAsync, GetAsync, and DeleteAsync surface.
  • Record schema: Annotated Entry with VectorStoreKey, VectorStoreData, and VectorStoreVector attributes.
  • Pluggable metrics: Retained IDistanceMetric, CosineSimilarity, and DotProduct, now using spans for allocation-free TensorPrimitives calls.
  • Evaluator integration: Updated Program.cs to resolve the collection from the store and consume VectorSearchResult<Entry> records and scores.
  • Windows UTF-8 handling: Dynamic tool loading now launches azmcp tools list under Windows code page 65001 and decodes redirected stdout and stderr as UTF-8. This prevents Unicode characters such as from being emitted as the invalid JSON control byte 0x1A; Linux and macOS retain direct process execution.
  • Packaging and solution setup: Added Microsoft.Extensions.VectorData.Abstractions through central package management and registered the new unit-test project in the relevant solutions.
  • Tests: Added focused coverage for vector-store collection operations, search behavior, batching, concurrency, and distance metrics.

Notes

  • GetAsync(Expression<...>) intentionally throws NotSupportedException; implementing it requires Expression.Compile(), which is incompatible with AOT. The evaluator does not use this overload.
  • Parallel search caps merged results at top; ranking of the requested results remains unchanged.
  • ProcessStartInfo.StandardOutputEncoding controls parent-side decoding only. The Windows wrapper is also required to make the child process emit UTF-8 rather than OEM code-page bytes.

Validation

  • Azure.Mcp.Server.csproj and ToolDescriptionEvaluator.sln build successfully.
  • All 28 ToolDescriptionEvaluator.UnitTests pass.
  • .\scripts\Run-ToolDescriptionEvaluator.ps1 -Area "keyvault" dynamically loaded and saved all 340 tools without the previous JSON deserialization failure. Full scoring still requires valid Azure OpenAI credentials.

Invoking Livetests

Copilot submitted PRs are not trustworthy by default. Users with write access to the repo need to validate the contents of this PR before leaving a comment with the text /azp run mcp - pullrequest - live. This will trigger the necessary livetest workflows to complete required validation.

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).
There may be pipelines that require an authorized user to comment /azp run to run.

Copilot AI changed the title [WIP] Make VectorDB an implementation of Microsoft.Extensions.VectorData Reimplement ToolDescriptionEvaluator VectorDB on Microsoft.Extensions.VectorData Jul 16, 2026
Copilot AI requested a review from vcolin7 July 16, 2026 00:42
@vcolin7 vcolin7 added this to the 2026-07 milestone Jul 21, 2026
@vcolin7

vcolin7 commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

@copilot Pull the latest changes from main into this branch. That'll take care of the failing pipelines

Copilot AI commented Jul 21, 2026

Copy link
Copy Markdown
Contributor Author

@copilot Pull the latest changes from main into this branch. That'll take care of the failing pipelines

Merged the latest main into this branch in 3204634 — clean merge with no conflicts, and the VectorDB work is intact.

@vcolin7

vcolin7 commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

@copilot Review and streamline the unit tests added for ToolDescriptionEvaluator in this PR. Remove tests that only verify TensorPrimitives/vector mathematics, trivial property forwarding, or behavior already covered more thoroughly elsewhere.

Make these changes:

  1. Delete CosineSimilarityTests.cs and DotProductTests.cs. These primarily test existing TensorPrimitives behavior and pre-existing wrappers rather than the VectorData re-implementation.
  2. In InMemoryVectorStoreCollectionTests.cs, remove:
    • Name_ReturnsProvidedName
    • CollectionExistsAsync_ReturnsTrue
    • SearchAsync_WithManyEntries_UsesParallelPathAndKeepsRanking
      Keep SearchAsync_ParallelPathMatchesIndependentRanking as the stronger parallel-search test.
  3. In VectorDBTests.cs, remove:
    • DefaultCollection_UsesDefaultCollectionName
    • DefaultCollection_ReturnsSameInstance
      The named-collection caching test already covers instance reuse more generally.
  4. Strengthen GetService_ReturnsStoreMetadata to verify VectorStoreSystemName is "InMemory", rather than only checking the returned type.
  5. Remove Store_And_Collection_WorkTogetherEndToEnd if it adds no behavior beyond the existing store and collection tests.
  6. Update the test project or solution if deleting the metric test files requires explicit reference cleanup.

Preserve tests covering custom behavior: sorted upsert/update/delete operations, batch upsert, top-K truncation, score thresholds, supported and unsupported search inputs, validation, unsupported VectorData operations, collection management, type restrictions, and the parallel merge algorithm.

Do not change production behavior or perform unrelated cleanup. Run the smallest applicable ToolDescriptionEvaluator unit-test command and ensure the project still builds and all remaining tests pass.

Copilot AI commented Jul 22, 2026

Copy link
Copy Markdown
Contributor Author

@copilot Review and streamline the unit tests added for ToolDescriptionEvaluator in this PR. Remove tests that only verify TensorPrimitives/vector mathematics, trivial property forward...

Addressed in ef0cbda. Removed the redundant metric/property/parallel/end-to-end tests, strengthened the store metadata assertion to verify VectorStoreSystemName == "InMemory", and kept the remaining custom-behavior coverage. The evaluator solution builds cleanly and all 28 retained tests pass.

@vcolin7
vcolin7 marked this pull request as ready for review July 22, 2026 05:24
@vcolin7
vcolin7 requested a review from a team as a code owner July 22, 2026 05:24
Copilot AI review requested due to automatic review settings July 22, 2026 05:24
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).
There may be pipelines that require an authorized user to comment /azp run to run.

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

This PR refactors the ToolDescriptionEvaluator in-memory vector database to implement the Microsoft.Extensions.VectorData abstractions, enabling provider-swappability (e.g., Azure AI Search/Cosmos DB/Redis) while preserving the existing brute-force similarity search behavior and updating the CLI to use the new async collection APIs.

Changes:

  • Reworked the in-memory vector store to derive from VectorStore and expose VectorStoreCollection<string, Entry>-compatible collections.
  • Updated the evaluator (Program.cs) to populate and query via UpsertAsync/SearchAsync and consume VectorSearchResult<Entry> (Record/Score).
  • Added unit test project and coverage for VectorDB and InMemoryVectorStoreCollection, and added Microsoft.Extensions.VectorData.Abstractions via central package management.

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
Microsoft.Mcp.slnx Adds the ToolDescriptionEvaluator unit test project to the main solution structure.
eng/tools/ToolDescriptionEvaluator/ToolDescriptionEvaluator.sln Adds unit test project and expands solution configurations.
eng/tools/ToolDescriptionEvaluator/tests/ToolDescriptionEvaluator.UnitTests/VectorDBTests.cs New unit tests validating VectorDB store behavior and metadata.
eng/tools/ToolDescriptionEvaluator/tests/ToolDescriptionEvaluator.UnitTests/InMemoryVectorStoreCollectionTests.cs New unit tests validating collection upsert/get/delete/search semantics.
eng/tools/ToolDescriptionEvaluator/tests/ToolDescriptionEvaluator.UnitTests/ToolDescriptionEvaluator.UnitTests.csproj Adds the new unit test project definition and references.
eng/tools/ToolDescriptionEvaluator/src/VectorDb/VectorDB.cs Implements VectorStore + VectorStoreCollection in-memory store/collection, span-based metrics, and vector search.
eng/tools/ToolDescriptionEvaluator/src/ToolDescriptionEvaluator.csproj Adds Microsoft.Extensions.VectorData.Abstractions dependency.
eng/tools/ToolDescriptionEvaluator/src/Program.cs Migrates evaluator logic to async VectorData collection APIs and adjusts output/process encoding behavior.
Directory.Packages.props Adds central package version for Microsoft.Extensions.VectorData.Abstractions.

Comment on lines +100 to +108
public override VectorStoreCollection<TKey, TRecord> GetCollection<TKey, TRecord>(string name, VectorStoreCollectionDefinition? definition = null)
{
if (typeof(TKey) != typeof(string) || typeof(TRecord) != typeof(Entry))
{
throw new NotSupportedException($"This store only supports collections of <{nameof(String)}, {nameof(Entry)}>.");
}

return (VectorStoreCollection<TKey, TRecord>)(object)GetOrCreateCollection(name);
}
Comment on lines +469 to +473
private IComparer<VectorSearchResult<Entry>> ResultComparer => Comparer<VectorSearchResult<Entry>>.Create((a, b) =>
{
int result = Nullable.Compare(a.Score, b.Score);
return _distanceMetric.BiggerIsCloser ? -result : result;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Make VectorDB an implementation of Microsoft.Extensions.VectorData

3 participants