Conversation
- 新增 AutoEmbeddingFieldAttribute,支持 Atlas 自动嵌入字段(Voyage AI 模型,零代码生成向量) - MongoSearchIndexAttribute 增加 StoredSource,支持原文档存储 - VectorFieldAttribute 支持自动量化(Scalar/Binary)、HNSW 图参数 - 新增 EVectorQuantization 枚举,索引定义生成逻辑同步增强 - 启动时自动对齐/更新索引定义,避免误判反复重建 - 变更流支持 ResumeTokenPersistInterval 节流,提升高并发场景性能,持久化逻辑更健壮 - 文档/示例同步完善,补充新特性说明与最佳实践 - IndexDefinition 实现 IEquatable,注释中英文补全
Contributor
There was a problem hiding this comment.
Pull request overview
EN
Summary
- Enhances EasilyNET.Mongo Atlas Search/Vector Search index definition generation (auto-embedding, stored source, vector quantization/HNSW options) and improves change stream resiliency/performance via resume-token persistence throttling, with accompanying docs updates.
Key issues
CollectAutoEmbeddingFieldsdoes not validate the annotated property type isstring, which can generate an invalid index definition and fail index creation/update at startup.- New HNSW tuning options accept negative values silently (treated like
0), making misconfiguration harder to detect.
Suggested changes
- Add an explicit
prop.PropertyType == typeof(string)validation forAutoEmbeddingFieldAttributemappings. - Validate
MaxEdges/NumEdgeCandidatesare>= 0and throw on negative values.
中文
总结
- 本 PR 增强 EasilyNET.Mongo 的 Atlas Search/Vector Search 索引定义生成能力(自动嵌入、StoredSource、量化/HNSW 参数),并通过 ResumeToken 持久化节流提升变更流在高并发场景下的性能与健壮性,同时完善文档示例。
主要问题
CollectAutoEmbeddingFields未校验属性类型是否为string,一旦误标注到非字符串字段,将生成非法索引定义并导致启动期索引创建/更新失败。- HNSW 参数新增后对负数输入会静默忽略(等价 0),不利于及时发现配置错误。
修改建议
- 为自动嵌入字段增加
string类型校验并给出明确异常信息。 - 对
MaxEdges/NumEdgeCandidates增加>= 0校验,负数直接抛异常。
Changes:
- Add
AutoEmbeddingFieldAttribute,StoredSource, vector quantization + HNSW options in index definition generation. - Add index definition drift reconciliation using server
latestDefinitionsubset-satisfaction comparison. - Add change-stream resume token persistence throttling (
ResumeTokenPersistInterval) and switch toStartAfterresume semantics; update docs accordingly.
Reviewed changes
Copilot reviewed 12 out of 13 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| src/EasilyNET.Mongo/SearchIndex/SearchIndexManager.cs | Adds subset-based definition satisfaction comparison to avoid unnecessary rebuilds and support drift detection. |
| src/EasilyNET.Mongo/SearchIndex/SearchIndexDefinitionFactory.cs | Generates new index definition fields: storedSource, quantization, HNSW options, and auto-embedding mappings. |
| src/EasilyNET.Mongo/SearchIndex/SearchIndexBackgroundService.cs | Reconciles index definition drift on startup and triggers updates when needed. |
| src/EasilyNET.Mongo/README.md | Updates usage docs/examples for StoredSource, quantization, auto-embedding, and change stream throttling semantics. |
| src/EasilyNET.Mongo/Options/ChangeStreamHandlerOptions.cs | Introduces ResumeTokenPersistInterval option with bilingual XML docs. |
| src/EasilyNET.Mongo/Indexing/IndexDefinition.cs | Implements IEquatable, adds Equals(object) and GetHashCode(). |
| src/EasilyNET.Mongo/ChangeStreams/MongoChangeStreamHandler.cs | Adds throttled resume-token persistence and switches to StartAfter; flushes pending token on shutdown/error. |
| src/EasilyNET.Mongo.Core/README.md | Documents EVectorQuantization, HNSW parameters, and AutoEmbeddingFieldAttribute usage. |
| src/EasilyNET.Mongo.Core/Enums/EVectorQuantization.cs | Adds quantization enum with bilingual docs. |
| src/EasilyNET.Mongo.Core/Attributes/VectorFieldAttribute.cs | Extends vector field attribute with quantization and HNSW tuning options. |
| src/EasilyNET.Mongo.Core/Attributes/MongoSearchIndexAttribute.cs | Adds StoredSource flag with bilingual docs. |
| src/EasilyNET.Mongo.Core/Attributes/AutoEmbeddingFieldAttribute.cs | Adds new attribute for Atlas automated embedding with bilingual docs and examples. |
| .gitignore | Ignores .omc files. |
本次更新在 SearchIndexDefinitionFactory.cs 中: - 增加了对 VectorFieldAttribute 的 MaxEdges 和 NumEdgeCandidates 非负校验; - 增加了对 AutoEmbeddingFieldAttribute 标注字段类型为 string 的强制校验; - 有助于及早发现配置错误,提升索引定义的健壮性和可维护性。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
📝 描述 (Description)
🔗 相关问题 (Related Issues)
🏷️ 变更类型 (Type of Change)
✅ 检查清单 (Checklist)
feature works)
🧪 测试 (Testing)
📸 截图 (如果适用) (Screenshots (if applicable))
🔍 附加说明 (Additional Notes)