Skip to content

Features/refine knowledge service#1341

Draft
iceljc wants to merge 28 commits intoSciSharp:masterfrom
iceljc:features/refine-knowledge-service
Draft

Features/refine knowledge service#1341
iceljc wants to merge 28 commits intoSciSharp:masterfrom
iceljc:features/refine-knowledge-service

Conversation

@iceljc
Copy link
Copy Markdown
Collaborator

@iceljc iceljc commented May 2, 2026

No description provided.

@qodo-code-review
Copy link
Copy Markdown
Contributor

Review Summary by Qodo

Refactor knowledge service architecture to support multiple knowledge types with improved separation of concerns

✨ Enhancement 🐞 Bug fix

Grey Divider

Walkthroughs

Description
• **Refactored knowledge service architecture** to support multiple knowledge types (Document,
  QuestionAnswer, SemanticGraph, Taxonomy) through dynamic service resolution instead of static
  dependencies
• **Renamed terminology** throughout codebase from "vector" to "collection" for consistency and
  clarity
• **Extracted file handling logic** into dedicated IKnowledgeFileOrchestrator service for better
  separation of concerns
• **Implemented type-specific knowledge services**: DocumentKnowledgeBase,
  QuestionAnswerKnowledgeBase, SementicGraphKnowledgeBase, and TaxonomyKnowledgeBase
• **Reorganized vector knowledge base** into modular partial classes: Collection.cs, Data.cs,
  Index.cs, and Snapshot.cs
• **Fixed naming inconsistencies** across repositories and storage services: corrected typos
  (VectorStroageProvidersVectorStorageProviders), renamed models (KnowledgeDocMetaDataKnowledgeFileMetaData), and standardized parameter names
• **Created comprehensive options and request models** for knowledge operations with proper
  inheritance hierarchy
• **Updated controller endpoints** to use dynamic knowledge service resolution based on
  knowledgeType parameter
• **Simplified vector search parameters** from VectorSearchParamModel to `Dictionary<string,
  string?>`
• **Added database provider support** throughout knowledge operations for multi-database scenarios
Diagram
flowchart LR
  A["Old Monolithic<br/>KnowledgeService"] -->|"Refactored into"| B["IKnowledgeService<br/>Interface"]
  B -->|"Implemented by"| C["DocumentKnowledgeBase"]
  B -->|"Implemented by"| D["QuestionAnswerKnowledgeBase"]
  B -->|"Implemented by"| E["SementicGraphKnowledgeBase"]
  B -->|"Implemented by"| F["TaxonomyKnowledgeBase"]
  C -->|"Extends"| G["VectorKnowledgeBase"]
  D -->|"Extends"| G
  H["IKnowledgeFileOrchestrator"] -->|"Extracted from"| A
  I["KnowledgeBaseController"] -->|"Uses dynamic<br/>resolution"| B
  J["KnowledgeHook"] -->|"Uses dynamic<br/>resolution"| B
Loading

Grey Divider

File Changes

1. src/Infrastructure/BotSharp.OpenAPI/Controllers/KnowledgeBase/KnowledgeBaseController.cs ✨ Enhancement +305/-114

Refactor knowledge service to support multiple knowledge types

• Refactored controller to use dynamic IKnowledgeService resolution based on knowledgeType query
 parameter instead of injected dependencies
• Renamed all endpoints from "vector" to "collection" terminology and updated method signatures
• Added BuildSearchOptions helper method to construct knowledge-specific search options (Graph,
 Taxonomy, Vector)
• Removed direct IGraphKnowledgeService dependency and integrated graph knowledge into unified
 service pattern

src/Infrastructure/BotSharp.OpenAPI/Controllers/KnowledgeBase/KnowledgeBaseController.cs


2. src/Plugins/BotSharp.Plugin.KnowledgeBase/Services/File/KnowledgeFileOrchestrator.cs ✨ Enhancement +114/-60

Extract file orchestration into dedicated service class

• Extracted file handling logic into new KnowledgeFileOrchestrator class implementing
 IKnowledgeFileOrchestrator
• Renamed methods from "Document" to "File" terminology (e.g., UploadDocumentsToKnowledgeUploadFilesToKnowledge)
• Updated method signatures to use new options classes (KnowledgeFileHandleOptions,
 ImportKnowledgeFileOptions, KnowledgeFileOptions)
• Added support for DbProvider parameter throughout file operations

src/Plugins/BotSharp.Plugin.KnowledgeBase/Services/File/KnowledgeFileOrchestrator.cs


3. src/Plugins/BotSharp.Plugin.KnowledgeBase/Services/Base/Vector/VectorKnowledgeBase.Data.cs ✨ Enhancement +230/-0

Add vector knowledge base data operations

• New file containing data operation methods for vector-based knowledge bases
• Implements collection data CRUD operations: CreateCollectionData, UpdateCollectionData,
 DeleteCollectionData
• Implements query execution via ExecuteQuery method with vector embedding and search
• Supports pagination via GetPagedCollectionData method

src/Plugins/BotSharp.Plugin.KnowledgeBase/Services/Base/Vector/VectorKnowledgeBase.Data.cs


View more (105)
4. src/Infrastructure/BotSharp.Abstraction/Knowledges/IKnowledgeService.cs ✨ Enhancement +45/-67

Refactor knowledge service interface for multi-type support

• Added KnowledgeType property to identify service type
• Replaced vector-specific methods with generic collection-based methods
• Removed document-related methods (moved to IKnowledgeFileOrchestrator)
• Added default implementations for all interface methods returning empty results
• Reorganized methods into sections: Collection, Data, Index, Snapshot

src/Infrastructure/BotSharp.Abstraction/Knowledges/IKnowledgeService.cs


5. src/Plugins/BotSharp.Plugin.KnowledgeBase/Hooks/KnowledgeHook.cs ✨ Enhancement +33/-47

Update knowledge hook for dynamic service resolution

• Removed injected IKnowledgeService and IGraphKnowledgeService dependencies
• Updated to dynamically resolve knowledge services using GetKnowledgeService helper method
• Changed knowledge type comparisons to use KnowledgeBaseType enum constants
• Simplified logic by using unified ExecuteQuery method across different knowledge types

src/Plugins/BotSharp.Plugin.KnowledgeBase/Hooks/KnowledgeHook.cs


6. src/Infrastructure/BotSharp.Core/Repository/FileRepository/FileRepository.KnowledgeBase.cs 🐞 Bug fix +16/-16

Fix naming inconsistencies in knowledge base repository

• Fixed typo: VectorStroageProvidersVectorStorageProviders
• Updated parameter names from vectorStroageProvider to knowledgebaseProvider
• Renamed model class from KnowledgeDocMetaData to KnowledgeFileMetaData

src/Infrastructure/BotSharp.Core/Repository/FileRepository/FileRepository.KnowledgeBase.cs


7. src/Infrastructure/BotSharp.Core/Files/Services/Storage/LocalFileStorageService.KnowledgeBase.cs 🐞 Bug fix +15/-15

Standardize parameter naming in local file storage

• Updated parameter names from vectorStoreProvider to knowledgebaseProvider for consistency
• Fixed typo in variable name: fileStoreagefileStorage

src/Infrastructure/BotSharp.Core/Files/Services/Storage/LocalFileStorageService.KnowledgeBase.cs


8. src/Infrastructure/BotSharp.OpenAPI/Controllers/KnowledgeBase/KnowledgeBaseController.File.cs ✨ Enhancement +102/-0

Add knowledge base file management endpoints

• New file containing file-related endpoints for knowledge base operations
• Implements endpoints for uploading, deleting, and retrieving knowledge files
• Supports both JSON and form-based file uploads
• Includes processor listing endpoint and file orchestrator resolution logic

src/Infrastructure/BotSharp.OpenAPI/Controllers/KnowledgeBase/KnowledgeBaseController.File.cs


9. src/Plugins/BotSharp.Plugin.KnowledgeBase/Services/Base/Vector/VectorKnowledgeBase.Collection.cs ✨ Enhancement +159/-0

Add vector knowledge base collection operations

• New file implementing collection management methods for vector knowledge bases
• Implements ExistCollection, CreateCollection, GetCollections, GetCollectionDetails,
 DeleteCollection
• Integrates with repository and file storage for collection lifecycle management

src/Plugins/BotSharp.Plugin.KnowledgeBase/Services/Base/Vector/VectorKnowledgeBase.Collection.cs


10. src/Plugins/BotSharp.Plugin.MongoStorage/Repository/MongoRepository.KnowledgeBase.cs 🐞 Bug fix +14/-14

Fix naming inconsistencies in MongoDB repository

• Fixed typo: VectorStroageProvidersVectorStorageProviders
• Updated parameter names from vectorStroageProvider to knowledgebaseProvider
• Renamed model class from KnowledgeDocMetaData to KnowledgeFileMetaData

src/Plugins/BotSharp.Plugin.MongoStorage/Repository/MongoRepository.KnowledgeBase.cs


11. src/Plugins/BotSharp.Plugin.TencentCos/Services/TencentCosService.KnowledgeBase.cs 🐞 Bug fix +14/-14

Standardize parameter naming in Tencent COS storage

• Updated parameter names from vectorStoreProvider to knowledgebaseProvider
• Maintained consistent naming across Tencent COS file storage implementation

src/Plugins/BotSharp.Plugin.TencentCos/Services/TencentCosService.KnowledgeBase.cs


12. src/Plugins/BotSharp.Plugin.KnowledgeBase/Services/Taxonomy/TaxonomyKnowledgeBase.cs ✨ Enhancement +108/-0

Add taxonomy knowledge base implementation

• New file implementing taxonomy-based knowledge service
• Implements ExecuteQuery using entity analyzer for taxonomy analysis
• Supports confidence scoring and result limiting
• Handles data provider and ngram configuration options

src/Plugins/BotSharp.Plugin.KnowledgeBase/Services/Taxonomy/TaxonomyKnowledgeBase.cs


13. src/Plugins/BotSharp.Plugin.KnowledgeBase/Services/Base/Vector/VectorKnowledgeBase.Snapshot.cs ✨ Enhancement +91/-0

Add vector knowledge base snapshot operations

• New file implementing snapshot operations for vector knowledge bases
• Implements GetCollectionSnapshots, CreateCollectionSnapshot, DownloadCollectionSnapshot,
 RecoverCollectionFromSnapshot, DeleteCollectionSnapshot

src/Plugins/BotSharp.Plugin.KnowledgeBase/Services/Base/Vector/VectorKnowledgeBase.Snapshot.cs


14. src/Infrastructure/BotSharp.Abstraction/Knowledges/IKnowledgeFileOrchestrator.cs ✨ Enhancement +65/-0

Add knowledge file orchestrator interface

• New interface for file orchestration operations
• Defines methods for uploading, importing, deleting, and retrieving knowledge files
• Includes Provider property for service identification

src/Infrastructure/BotSharp.Abstraction/Knowledges/IKnowledgeFileOrchestrator.cs


15. src/Plugins/BotSharp.Plugin.KnowledgeBase/Services/Base/Vector/VectorKnowledgeBase.Index.cs ✨ Enhancement +82/-0

Add vector knowledge base index operations

• New file implementing index management for vector knowledge bases
• Implements CreateIndexes and DeleteIndexes methods with success/failure tracking

src/Plugins/BotSharp.Plugin.KnowledgeBase/Services/Base/Vector/VectorKnowledgeBase.Index.cs


16. src/Plugins/BotSharp.Plugin.KnowledgeBase/Services/Graph/SementicGraphKnowledgeBase.cs ✨ Enhancement +63/-0

Add semantic graph knowledge base implementation

• New file implementing semantic graph knowledge service
• Implements ExecuteQuery using graph database for relationship-based queries
• Converts graph results to unified KnowledgeExecuteResult format

src/Plugins/BotSharp.Plugin.KnowledgeBase/Services/Graph/SementicGraphKnowledgeBase.cs


17. src/Infrastructure/BotSharp.OpenAPI/ViewModels/Knowledges/View/KnowledgeKnowledgeViewModel.cs ✨ Enhancement +29/-5

Rename and extend knowledge view model

• Renamed class from VectorKnowledgeViewModel to KnowledgeKnowledgeViewModel
• Added overloads for From method supporting KnowledgeExecuteResult and
 KnowledgeCollectionData

src/Infrastructure/BotSharp.OpenAPI/ViewModels/Knowledges/View/KnowledgeKnowledgeViewModel.cs


18. src/Infrastructure/BotSharp.Abstraction/Repositories/IBotSharpRepository.cs 🐞 Bug fix +4/-11

Update repository interface naming conventions

• Updated parameter names from vectorStroageProvider to knowledgebaseProvider
• Renamed model class from KnowledgeDocMetaData to KnowledgeFileMetaData
• Removed redundant XML documentation comments

src/Infrastructure/BotSharp.Abstraction/Repositories/IBotSharpRepository.cs


19. src/Infrastructure/BotSharp.Abstraction/Files/IFileStorageService.cs 🐞 Bug fix +4/-12

Standardize file storage service interface naming

• Updated parameter names from vectorStoreProvider to knowledgebaseProvider
• Removed redundant XML documentation comments

src/Infrastructure/BotSharp.Abstraction/Files/IFileStorageService.cs


20. src/Infrastructure/BotSharp.OpenAPI/ViewModels/Knowledges/View/KnowledgeCollectionSnapshotViewModel.cs ✨ Enhancement +52/-0

Add knowledge collection snapshot view model

• New file containing snapshot view model with JSON serialization attributes
• Includes From factory methods for both VectorCollectionSnapshot and
 KnowledgeCollectionSnapshot

src/Infrastructure/BotSharp.OpenAPI/ViewModels/Knowledges/View/KnowledgeCollectionSnapshotViewModel.cs


21. src/Plugins/BotSharp.Plugin.SqlDriver/Services/DbKnowledgeService.cs ✨ Enhancement +6/-6

Update SQL driver for new knowledge service pattern

• Updated to dynamically resolve IKnowledgeService by KnowledgeBaseType.QuestionAnswer
• Changed method calls from CreateVectorCollectionData to CreateCollectionData
• Updated model class from VectorCreateModel to KnowledgeCreateModel

src/Plugins/BotSharp.Plugin.SqlDriver/Services/DbKnowledgeService.cs


22. src/Plugins/BotSharp.Plugin.Qdrant/QdrantDb.cs ✨ Enhancement +6/-5

Update Qdrant database for new index options

• Updated method signatures: CreateVectorCollectionIndexOptionsCollectionIndexOptions
• Changed BuildSearchParam to accept Dictionary<string, string> instead of
 VectorSearchParamModel

src/Plugins/BotSharp.Plugin.Qdrant/QdrantDb.cs


23. tests/BotSharp.LLM.Tests/Core/NullFileStorageService.cs 🧪 Tests +4/-4

Update test mock file storage naming

• Updated parameter names from vectorStoreProvider to knowledgebaseProvider in test mock

tests/BotSharp.LLM.Tests/Core/NullFileStorageService.cs


24. src/Infrastructure/BotSharp.OpenAPI/ViewModels/Knowledges/Request/KnowledgeExecuteRequest.cs ✨ Enhancement +34/-0

Add knowledge execute request model

• New file defining request model for knowledge query execution
• Extends KnowledgeBaseRequestBase with search parameters, filters, and knowledge-type-specific
 options

src/Infrastructure/BotSharp.OpenAPI/ViewModels/Knowledges/Request/KnowledgeExecuteRequest.cs


25. src/Plugins/BotSharp.Plugin.KnowledgeBase/Services/Base/Vector/VectorKnowledgeBase.cs ✨ Enhancement +40/-0

Add abstract vector knowledge base class

• New abstract base class for vector-based knowledge services
• Provides common functionality: vector database resolution, text embedding, user identification
• Defines abstract KnowledgeType property for subclass implementation

src/Plugins/BotSharp.Plugin.KnowledgeBase/Services/Base/Vector/VectorKnowledgeBase.cs


26. src/Infrastructure/BotSharp.Abstraction/Knowledges/Models/KnowledgeFilter.cs ✨ Enhancement +29/-0

Add knowledge filter model

• New file defining filter model for knowledge collection queries
• Supports pagination, vector inclusion, filtering, sorting, and field selection

src/Infrastructure/BotSharp.Abstraction/Knowledges/Models/KnowledgeFilter.cs


27. src/Infrastructure/BotSharp.Abstraction/Knowledges/Models/KnowledgeCollectionSnapshot.cs ✨ Enhancement +4/-12

Move snapshot model to abstraction layer

• Moved from view model to abstraction layer
• Renamed from VectorCollectionSnapshotViewModel to KnowledgeCollectionSnapshot
• Added CopyFrom factory method for conversion from VectorCollectionSnapshot

src/Infrastructure/BotSharp.Abstraction/Knowledges/Models/KnowledgeCollectionSnapshot.cs


28. src/Plugins/BotSharp.Plugin.KnowledgeBase/Functions/MemorizeKnowledgeFn.cs ✨ Enhancement +13/-4

Update memorize function for new knowledge service

• Updated to dynamically resolve knowledge service by KnowledgeBaseType.QuestionAnswer
• Changed method call from CreateVectorCollectionData to CreateCollectionData
• Updated model class from VectorCreateModel to KnowledgeCreateModel

src/Plugins/BotSharp.Plugin.KnowledgeBase/Functions/MemorizeKnowledgeFn.cs


29. src/Infrastructure/BotSharp.Core/Using.cs ⚙️ Configuration changes +1/-0

Add knowledge options namespace to global usings

• Added global using for BotSharp.Abstraction.Knowledges.Options

src/Infrastructure/BotSharp.Core/Using.cs


30. src/Infrastructure/BotSharp.Abstraction/Using.cs ⚙️ Configuration changes +1/-0

Add knowledge options namespace to global usings

• Added global using for BotSharp.Abstraction.Knowledges.Options

src/Infrastructure/BotSharp.Abstraction/Using.cs


31. src/Plugins/BotSharp.Plugin.KnowledgeBase/KnowledgeBasePlugin.cs ⚙️ Configuration changes +7/-1

Register multiple knowledge service implementations

• Registered multiple IKnowledgeService implementations: DocumentKnowledgeBase,
 QuestionAnswerKnowledgeBase, SementicGraphKnowledgeBase, TaxonomyKnowledgeBase
• Registered IKnowledgeFileOrchestrator implementation: KnowledgeFileOrchestrator
• Removed single KnowledgeService registration

src/Plugins/BotSharp.Plugin.KnowledgeBase/KnowledgeBasePlugin.cs


32. src/Infrastructure/BotSharp.Abstraction/Knowledges/Options/KnowledgeExecuteOptions.cs ✨ Enhancement +16/-0

Add knowledge execute options class

• New file defining options for knowledge query execution
• Includes database provider, search parameters, filters, and result configuration

src/Infrastructure/BotSharp.Abstraction/Knowledges/Options/KnowledgeExecuteOptions.cs


33. src/Infrastructure/BotSharp.Abstraction/VectorStorage/IVectorDb.cs ✨ Enhancement +2/-2

Update vector database interface for index options

• Updated method signatures: CreateVectorCollectionIndexOptionsCollectionIndexOptions
• Updated method signatures: DeleteVectorCollectionIndexOptionsCollectionIndexOptions

src/Infrastructure/BotSharp.Abstraction/VectorStorage/IVectorDb.cs


34. src/Infrastructure/BotSharp.Abstraction/VectorStorage/Options/VectorSearchOptions.cs ✨ Enhancement +1/-1

Simplify vector search parameter type

• Changed SearchParam type from VectorSearchParamModel to Dictionary<string, string?>

src/Infrastructure/BotSharp.Abstraction/VectorStorage/Options/VectorSearchOptions.cs


35. src/Infrastructure/BotSharp.Abstraction/Knowledges/Models/KnowledgeCollectionData.cs ✨ Enhancement +14/-0

Add knowledge collection data model

• New file defining model for knowledge collection data items
• Includes payload, data dictionary, score, and optional vector

src/Infrastructure/BotSharp.Abstraction/Knowledges/Models/KnowledgeCollectionData.cs


36. src/Infrastructure/BotSharp.OpenAPI/ViewModels/Knowledges/View/KnowledgeCollectionDetailsViewModel.cs ✨ Enhancement +3/-3

Rename collection details view model

• Renamed class from VectorCollectionDetailsViewModel to KnowledgeCollectionDetailsViewModel
• Updated From factory method name

src/Infrastructure/BotSharp.OpenAPI/ViewModels/Knowledges/View/KnowledgeCollectionDetailsViewModel.cs


37. src/Infrastructure/BotSharp.Abstraction/Knowledges/Models/KnowledgeExecuteResult.cs ✨ Enhancement +20/-0

Add knowledge execute result model

• New file defining result model for knowledge query execution
• Extends KnowledgeCollectionData with factory method for conversion

src/Infrastructure/BotSharp.Abstraction/Knowledges/Models/KnowledgeExecuteResult.cs


38. src/Infrastructure/BotSharp.OpenAPI/ViewModels/Knowledges/View/KnowledgeCollectionConfigViewModel.cs ✨ Enhancement +3/-3

Rename collection config view model

• Renamed class from VectorCollectionConfigViewModel to KnowledgeCollectionConfigViewModel
• Updated From factory method

src/Infrastructure/BotSharp.OpenAPI/ViewModels/Knowledges/View/KnowledgeCollectionConfigViewModel.cs


39. src/Infrastructure/BotSharp.OpenAPI/ViewModels/Knowledges/Request/CollectionIndexRequest.cs ✨ Enhancement +13/-0

Add collection index request models

• New file defining request models for index operations
• Includes CreateCollectionIndexRequest and DeleteCollectionIndexRequest extending
 KnowledgeBaseRequestBase

src/Infrastructure/BotSharp.OpenAPI/ViewModels/Knowledges/Request/CollectionIndexRequest.cs


40. src/Plugins/BotSharp.Plugin.KnowledgeBase/Services/QuestionAnswer/QuestionAnswerKnowledgeBase.cs ✨ Enhancement +14/-0

Add question-answer knowledge base implementation

• New file implementing question-answer knowledge service
• Extends VectorKnowledgeBase with KnowledgeType of QuestionAnswer

src/Plugins/BotSharp.Plugin.KnowledgeBase/Services/QuestionAnswer/QuestionAnswerKnowledgeBase.cs


41. src/Infrastructure/BotSharp.OpenAPI/ViewModels/Knowledges/Request/KnowledgeUploadRequest.cs ✨ Enhancement +13/-0

Add knowledge upload request model

• New file defining request model for knowledge file uploads
• Includes file orchestrator provider, files collection, and handling options

src/Infrastructure/BotSharp.OpenAPI/ViewModels/Knowledges/Request/KnowledgeUploadRequest.cs


42. src/Infrastructure/BotSharp.OpenAPI/ViewModels/Knowledges/Request/KnowledgeDataCreateRequest.cs Refactoring +1/-4

Refactor knowledge data creation request model

• Renamed class from VectorKnowledgeCreateRequest to KnowledgeDataCreateRequest
• Changed to inherit from KnowledgeBaseRequestBase base class
• Removed System.Text.Json.Serialization using statement
• Removed JsonPropertyName attributes from properties

src/Infrastructure/BotSharp.OpenAPI/ViewModels/Knowledges/Request/KnowledgeDataCreateRequest.cs


43. src/Infrastructure/BotSharp.Abstraction/Knowledges/Filters/KnowledgeFileFilter.cs ✨ Enhancement +1/-3

Add database provider to knowledge file filter

• Added new DbProvider property
• Removed extra blank lines between properties for cleaner formatting

src/Infrastructure/BotSharp.Abstraction/Knowledges/Filters/KnowledgeFileFilter.cs


44. src/Infrastructure/BotSharp.Abstraction/Entity/Models/EntityAnalysisOptions.cs Refactoring +1/-1

Change data providers to use interface type

• Changed DataProviders property type from List<string> to IEnumerable<string>

src/Infrastructure/BotSharp.Abstraction/Entity/Models/EntityAnalysisOptions.cs


45. src/Plugins/BotSharp.Plugin.KnowledgeBase/Services/Document/DocumentKnowledgeBase.cs ✨ Enhancement +14/-0

Create document knowledge base service implementation

• New file implementing DocumentKnowledgeBase class
• Inherits from VectorKnowledgeBase and implements IKnowledgeService
• Overrides KnowledgeType property to return KnowledgeBaseType.Document
• Provides constructor with dependency injection for services, logger, and settings

src/Plugins/BotSharp.Plugin.KnowledgeBase/Services/Document/DocumentKnowledgeBase.cs


46. src/Infrastructure/BotSharp.Abstraction/Knowledges/Models/KnowledgeCollectionDetails.cs ✨ Enhancement +12/-0

Add knowledge collection details model

• New model class for knowledge collection details
• Contains Status property with JSON serialization
• Contains PayloadSchema list initialized with empty array

src/Infrastructure/BotSharp.Abstraction/Knowledges/Models/KnowledgeCollectionDetails.cs


47. src/Infrastructure/BotSharp.Abstraction/VectorStorage/Filters/VectorCollectionConfigFilter.cs 🐞 Bug fix +1/-1

Fix typo in vector storage providers property

• Fixed typo in property name from VectorStroageProviders to VectorStorageProviders

src/Infrastructure/BotSharp.Abstraction/VectorStorage/Filters/VectorCollectionConfigFilter.cs


48. src/Plugins/BotSharp.Plugin.Qdrant/Using.cs Dependencies +2/-1

Add knowledge options namespace import

• Added new global using statement for BotSharp.Abstraction.Knowledges.Options
• Fixed file ending with newline

src/Plugins/BotSharp.Plugin.Qdrant/Using.cs


49. src/Infrastructure/BotSharp.Abstraction/VectorStorage/Extensions/VectorStorageExtension.cs Refactoring +1/-1

Update vector storage extension method parameter type

• Changed extension method parameter type from VectorSearchResult to KnowledgeExecuteResult

src/Infrastructure/BotSharp.Abstraction/VectorStorage/Extensions/VectorStorageExtension.cs


50. src/Infrastructure/BotSharp.OpenAPI/ViewModels/Knowledges/Request/QueryCollectionDataRequest.cs ✨ Enhancement +2/-1

Rename query request and add provider support

• Renamed class from QueryVectorDataRequest to QueryCollectionDataRequest
• Added new DbProvider property

src/Infrastructure/BotSharp.OpenAPI/ViewModels/Knowledges/Request/QueryCollectionDataRequest.cs


51. src/Infrastructure/BotSharp.Abstraction/VectorStorage/Options/CollectionIndexOptions.cs ✨ Enhancement +10/-0

Add collection index options model

• New options class for collection index configuration
• Contains FieldName and FieldSchemaType properties with JSON serialization

src/Infrastructure/BotSharp.Abstraction/VectorStorage/Options/CollectionIndexOptions.cs


52. src/Infrastructure/BotSharp.OpenAPI/ViewModels/Knowledges/Request/KnowledgeBaseRequestBase.cs ✨ Enhancement +11/-0

Create base class for knowledge requests

• New base class for knowledge-related API requests
• Contains KnowledgeType and optional DbProvider properties
• Includes JSON ignore attribute for null provider values

src/Infrastructure/BotSharp.OpenAPI/ViewModels/Knowledges/Request/KnowledgeBaseRequestBase.cs


53. src/Infrastructure/BotSharp.Abstraction/Knowledges/Options/ImportKnowledgeFileOptions.cs ✨ Enhancement +9/-0

Add knowledge file import options

• New options class for importing knowledge files
• Inherits from KnowledgeOptionBase
• Contains FileRefData and Payload properties

src/Infrastructure/BotSharp.Abstraction/Knowledges/Options/ImportKnowledgeFileOptions.cs


54. src/Infrastructure/BotSharp.OpenAPI/ViewModels/Knowledges/Request/CreateCollectionRequest.cs ✨ Enhancement +9/-0

Add create collection request model

• New request class for creating knowledge collections
• Inherits from KnowledgeBaseRequestBase
• Contains collection name, provider, model, and dimension properties

src/Infrastructure/BotSharp.OpenAPI/ViewModels/Knowledges/Request/CreateCollectionRequest.cs


55. src/Infrastructure/BotSharp.Abstraction/Knowledges/Enums/KnowledgeBaseType.cs ✨ Enhancement +3/-1

Rename and extend knowledge base type enumeration

• Renamed class from KnowledgeCollectionType to KnowledgeBaseType
• Added two new knowledge type constants: Taxonomy and SemanticGraph

src/Infrastructure/BotSharp.Abstraction/Knowledges/Enums/KnowledgeBaseType.cs


56. src/Infrastructure/BotSharp.Abstraction/Knowledges/Options/CollectionCreateOptions.cs ✨ Enhancement +8/-0

Add collection creation options

• New options class for creating knowledge collections
• Inherits from KnowledgeOptionBase
• Contains embedding dimension and LLM provider/model properties

src/Infrastructure/BotSharp.Abstraction/Knowledges/Options/CollectionCreateOptions.cs


57. src/Infrastructure/BotSharp.Abstraction/Knowledges/Options/KnowledgeQueryOptions.cs ✨ Enhancement +12/-0

Add knowledge query options

• New options class for knowledge queries
• Inherits from KnowledgeOptionBase
• Contains payload and vector inclusion flags with default factory method

src/Infrastructure/BotSharp.Abstraction/Knowledges/Options/KnowledgeQueryOptions.cs


58. src/Plugins/BotSharp.Plugin.SqlDriver/Using.cs Dependencies +1/-0

Add knowledge options namespace import

• Added global using statement for BotSharp.Abstraction.Knowledges.Options

src/Plugins/BotSharp.Plugin.SqlDriver/Using.cs


59. src/Infrastructure/BotSharp.Abstraction/Knowledges/Models/KnowledgeCreateModel.cs ✨ Enhancement +9/-0

Add knowledge creation model

• New model class for creating knowledge entries
• Inherits from KnowledgeOptionBase
• Contains Text and optional Payload properties

src/Infrastructure/BotSharp.Abstraction/Knowledges/Models/KnowledgeCreateModel.cs


60. src/Infrastructure/BotSharp.OpenAPI/Using.cs Dependencies +1/-0

Add knowledge options namespace import

• Added global using statement for BotSharp.Abstraction.Knowledges.Options

src/Infrastructure/BotSharp.OpenAPI/Using.cs


61. src/Infrastructure/BotSharp.Abstraction/VectorStorage/Models/VectorPayloadValue.cs ✨ Enhancement +1/-1

Add default parameter to payload value constructor

• Added default parameter value VectorPayloadDataType.Unknown to constructor

src/Infrastructure/BotSharp.Abstraction/VectorStorage/Models/VectorPayloadValue.cs


62. src/Infrastructure/BotSharp.Abstraction/Knowledges/Options/TaxonomyKnowledgeSearchOptions.cs ✨ Enhancement +7/-0

Add taxonomy knowledge search options

• New options class for taxonomy knowledge searches
• Inherits from KnowledgeExecuteOptions
• Contains data providers and max n-gram properties

src/Infrastructure/BotSharp.Abstraction/Knowledges/Options/TaxonomyKnowledgeSearchOptions.cs


63. src/Infrastructure/BotSharp.OpenAPI/ViewModels/Knowledges/Request/GetKnowledgeFilesRequest.cs ✨ Enhancement +8/-0

Add get knowledge files request model

• New request class for retrieving knowledge files
• Inherits from KnowledgeFileFilter
• Contains optional FileOrchestrator property

src/Infrastructure/BotSharp.OpenAPI/ViewModels/Knowledges/Request/GetKnowledgeFilesRequest.cs


64. src/Infrastructure/BotSharp.Abstraction/Knowledges/Options/KnowledgeIndexOptions.cs ✨ Enhancement +8/-0

Add knowledge index options

• New options class for knowledge indexing
• Inherits from KnowledgeOptionBase
• Contains collection of CollectionIndexOptions items

src/Infrastructure/BotSharp.Abstraction/Knowledges/Options/KnowledgeIndexOptions.cs


65. src/Infrastructure/BotSharp.OpenAPI/ViewModels/Knowledges/Request/KnowledgeCollectionConfigsRequest.cs ✨ Enhancement +8/-0

Add knowledge collection configs request

• New request class for knowledge collection configurations
• Contains list of VectorCollectionConfig items

src/Infrastructure/BotSharp.OpenAPI/ViewModels/Knowledges/Request/KnowledgeCollectionConfigsRequest.cs


66. src/Infrastructure/BotSharp.Abstraction/Knowledges/Options/KnowledgeFileHandleOptions.cs ✨ Enhancement +7/-0

Add knowledge file handle options

• New options class for handling knowledge files
• Inherits from FileKnowledgeHandleOptions
• Contains database provider and processor properties

src/Infrastructure/BotSharp.Abstraction/Knowledges/Options/KnowledgeFileHandleOptions.cs


67. src/Infrastructure/BotSharp.OpenAPI/ViewModels/Knowledges/Request/KnowledgeFileRequest.cs ✨ Enhancement +7/-0

Add knowledge file request model

• New request class for knowledge file operations
• Contains optional file orchestrator and database provider properties

src/Infrastructure/BotSharp.OpenAPI/ViewModels/Knowledges/Request/KnowledgeFileRequest.cs


68. src/Infrastructure/BotSharp.Abstraction/Knowledges/Models/KnowledgeFileMetaData.cs Refactoring +1/-1

Rename knowledge metadata class

• Renamed class from KnowledgeDocMetaData to KnowledgeFileMetaData

src/Infrastructure/BotSharp.Abstraction/Knowledges/Models/KnowledgeFileMetaData.cs


69. src/Infrastructure/BotSharp.OpenAPI/ViewModels/Knowledges/Request/DeleteCollectionSnapshotRequest.cs ✨ Enhancement +6/-0

Add delete collection snapshot request

• New request class for deleting collection snapshots
• Inherits from KnowledgeBaseRequestBase
• Contains snapshot name property

src/Infrastructure/BotSharp.OpenAPI/ViewModels/Knowledges/Request/DeleteCollectionSnapshotRequest.cs


70. src/Infrastructure/BotSharp.OpenAPI/ViewModels/Knowledges/Request/GetPagedCollectionDataRequest.cs ✨ Enhancement +6/-0

Add paged collection data request

• New request class for retrieving paged collection data
• Inherits from KnowledgeFilter
• Contains knowledge type property

src/Infrastructure/BotSharp.OpenAPI/ViewModels/Knowledges/Request/GetPagedCollectionDataRequest.cs


71. src/Infrastructure/BotSharp.Abstraction/Knowledges/Options/GraphKnowledgeSearchOptions.cs ✨ Enhancement +6/-0

Add graph knowledge search options

• New options class for graph knowledge searches
• Inherits from KnowledgeExecuteOptions
• Contains optional graph ID property

src/Infrastructure/BotSharp.Abstraction/Knowledges/Options/GraphKnowledgeSearchOptions.cs


72. src/Infrastructure/BotSharp.OpenAPI/ViewModels/Knowledges/Request/KnowledgeDataUpdateRequest.cs ✨ Enhancement +6/-0

Add knowledge data update request

• New request class for updating knowledge data
• Inherits from KnowledgeDataCreateRequest
• Contains ID property for identifying the record to update

src/Infrastructure/BotSharp.OpenAPI/ViewModels/Knowledges/Request/KnowledgeDataUpdateRequest.cs


73. src/Infrastructure/BotSharp.Abstraction/Knowledges/Models/KnowledgeCollectionConfigModel.cs ✨ Enhancement +7/-0

Add knowledge collection config model

• New model class for knowledge collection configuration
• Inherits from VectorCollectionConfig

src/Infrastructure/BotSharp.Abstraction/Knowledges/Models/KnowledgeCollectionConfigModel.cs


74. src/Infrastructure/BotSharp.Abstraction/Knowledges/Options/KnowledgeCollectionOptions.cs ✨ Enhancement +6/-0

Add knowledge collection options

• New options class for knowledge collections
• Inherits from KnowledgeOptionBase
• Contains flag to include all knowledge types

src/Infrastructure/BotSharp.Abstraction/Knowledges/Options/KnowledgeCollectionOptions.cs


75. src/Infrastructure/BotSharp.Abstraction/Knowledges/Models/KnowledgeUpdateModel.cs ✨ Enhancement +6/-0

Add knowledge update model

• New model class for updating knowledge entries
• Inherits from KnowledgeCreateModel
• Contains ID property for identifying the record to update

src/Infrastructure/BotSharp.Abstraction/Knowledges/Models/KnowledgeUpdateModel.cs


76. src/Infrastructure/BotSharp.Abstraction/Knowledges/Options/KnowledgeOptionBase.cs ✨ Enhancement +6/-0

Add base class for knowledge options

• New base class for all knowledge-related options
• Contains optional database provider property

src/Infrastructure/BotSharp.Abstraction/Knowledges/Options/KnowledgeOptionBase.cs


77. src/Infrastructure/BotSharp.OpenAPI/ViewModels/Knowledges/Request/DeleteCollectionDataRequest.cs ✨ Enhancement +5/-0

Add delete collection data request

• New request class for deleting collection data
• Inherits from KnowledgeBaseRequestBase

src/Infrastructure/BotSharp.OpenAPI/ViewModels/Knowledges/Request/DeleteCollectionDataRequest.cs


78. src/Infrastructure/BotSharp.OpenAPI/ViewModels/Knowledges/Request/CollectionSnapshotRequest.cs ✨ Enhancement +5/-0

Add collection snapshot request

• New request class for collection snapshot operations
• Inherits from KnowledgeBaseRequestBase

src/Infrastructure/BotSharp.OpenAPI/ViewModels/Knowledges/Request/CollectionSnapshotRequest.cs


79. src/Infrastructure/BotSharp.OpenAPI/ViewModels/Knowledges/Request/DeleteCollectionRequest.cs ✨ Enhancement +5/-0

Add delete collection request

• New request class for deleting collections
• Inherits from KnowledgeBaseRequestBase

src/Infrastructure/BotSharp.OpenAPI/ViewModels/Knowledges/Request/DeleteCollectionRequest.cs


80. src/Infrastructure/BotSharp.Abstraction/Knowledges/Options/KnowledgeFileOptions.cs ✨ Enhancement +5/-0

Add knowledge file options

• New options class for knowledge file operations
• Inherits from KnowledgeOptionBase

src/Infrastructure/BotSharp.Abstraction/Knowledges/Options/KnowledgeFileOptions.cs


81. src/Infrastructure/BotSharp.Abstraction/Knowledges/Options/KnowledgeSnapshotOptions.cs ✨ Enhancement +5/-0

Add knowledge snapshot options

• New options class for knowledge snapshots
• Inherits from KnowledgeOptionBase

src/Infrastructure/BotSharp.Abstraction/Knowledges/Options/KnowledgeSnapshotOptions.cs


82. src/Plugins/BotSharp.Plugin.FuzzySharp/FuzzySharpPlugin.cs Dependencies +1/-0

Add knowledge abstraction namespace import

• Added using statement for BotSharp.Abstraction.Knowledges namespace

src/Plugins/BotSharp.Plugin.FuzzySharp/FuzzySharpPlugin.cs


83. src/Plugins/BotSharp.Plugin.KnowledgeBase/BotSharp.Plugin.KnowledgeBase.csproj ⚙️ Configuration changes +5/-0

Add placeholder folders for graph and taxonomy services

• Added two new folder placeholders for future implementations: Services\Graph\ and
 Services\Taxonomy\

src/Plugins/BotSharp.Plugin.KnowledgeBase/BotSharp.Plugin.KnowledgeBase.csproj


84. src/Infrastructure/BotSharp.Abstraction/Knowledges/Options/KnowledgeDocOptions.cs Additional files +0/-6

...

src/Infrastructure/BotSharp.Abstraction/Knowledges/Options/KnowledgeDocOptions.cs


85. src/Infrastructure/BotSharp.Abstraction/Models/LlmConfigBase.cs Additional files +0/-5

...

src/Infrastructure/BotSharp.Abstraction/Models/LlmConfigBase.cs


86. src/Infrastructure/BotSharp.Abstraction/VectorStorage/Models/VectorCollectionConfigModel.cs Additional files +0/-6

...

src/Infrastructure/BotSharp.Abstraction/VectorStorage/Models/VectorCollectionConfigModel.cs


87. src/Infrastructure/BotSharp.Abstraction/VectorStorage/Models/VectorCreateModel.cs Additional files +0/-9

...

src/Infrastructure/BotSharp.Abstraction/VectorStorage/Models/VectorCreateModel.cs


88. src/Infrastructure/BotSharp.Abstraction/VectorStorage/Models/VectorSearchParamModel.cs Additional files +0/-7

...

src/Infrastructure/BotSharp.Abstraction/VectorStorage/Models/VectorSearchParamModel.cs


89. src/Infrastructure/BotSharp.Abstraction/VectorStorage/Models/VectorUpdateModel.cs Additional files +0/-6

...

src/Infrastructure/BotSharp.Abstraction/VectorStorage/Models/VectorUpdateModel.cs


90. src/Infrastructure/BotSharp.Abstraction/VectorStorage/Options/VectorCollectionIndexOptions.cs Additional files +0/-18

...

src/Infrastructure/BotSharp.Abstraction/VectorStorage/Options/VectorCollectionIndexOptions.cs


91. src/Infrastructure/BotSharp.OpenAPI/Controllers/KnowledgeBase/KnowledgeBaseController.Document.cs Additional files +0/-87

...

src/Infrastructure/BotSharp.OpenAPI/Controllers/KnowledgeBase/KnowledgeBaseController.Document.cs


92. src/Infrastructure/BotSharp.OpenAPI/Controllers/KnowledgeBase/KnowledgeBaseController.Entity.cs Additional files +0/-20

...

src/Infrastructure/BotSharp.OpenAPI/Controllers/KnowledgeBase/KnowledgeBaseController.Entity.cs


93. src/Infrastructure/BotSharp.OpenAPI/ViewModels/Knowledges/Request/CreateVectorCollectionRequest.cs Additional files +0/-21

...

src/Infrastructure/BotSharp.OpenAPI/ViewModels/Knowledges/Request/CreateVectorCollectionRequest.cs


94. src/Infrastructure/BotSharp.OpenAPI/ViewModels/Knowledges/Request/DeleteVectorCollectionSnapshotRequest.cs Additional files +0/-9

...

src/Infrastructure/BotSharp.OpenAPI/ViewModels/Knowledges/Request/DeleteVectorCollectionSnapshotRequest.cs


95. src/Infrastructure/BotSharp.OpenAPI/ViewModels/Knowledges/Request/EntityAnalysisRequest.cs Additional files +0/-8

...

src/Infrastructure/BotSharp.OpenAPI/ViewModels/Knowledges/Request/EntityAnalysisRequest.cs


96. src/Infrastructure/BotSharp.OpenAPI/ViewModels/Knowledges/Request/GetKnowledgeDocsRequest.cs Additional files +0/-7

...

src/Infrastructure/BotSharp.OpenAPI/ViewModels/Knowledges/Request/GetKnowledgeDocsRequest.cs


97. src/Infrastructure/BotSharp.OpenAPI/ViewModels/Knowledges/Request/SearchGraphKnowledgeReq...

@qodo-code-review
Copy link
Copy Markdown
Contributor

qodo-code-review Bot commented May 2, 2026

Code Review by Qodo

🐞 Bugs (4) 📘 Rule violations (5)

Grey Divider


Action required

1. BuildSearchOptions reuses request collections 📘 Rule violation ⛨ Security
Description
BuildSearchOptions assigns caller-provided collections/dictionaries (e.g., Fields,
FilterGroups, SearchArguments, DataProviders) directly onto option objects, allowing shared
mutable state between layers. This can let downstream mutations leak back into request objects and
across components.
Code

src/Infrastructure/BotSharp.OpenAPI/Controllers/KnowledgeBase/KnowledgeBaseController.cs[R395-434]

+    private KnowledgeExecuteOptions BuildSearchOptions(IKnowledgeService kg, KnowledgeExecuteRequest? request)
+    {
+        var searchParam = request?.SearchParam?.ToDictionary(x => x.Key, x => x.Value?.ConvertToString());
+
+        if (kg.KnowledgeType.IsEqualTo(KnowledgeBaseType.SemanticGraph))
+        {
+            return new GraphKnowledgeSearchOptions
+            {
+                DbProvider = request?.DbProvider,
+                SearchParam = searchParam,
+                SearchArguments = request?.SearchArguments,
+                GraphId = request?.GraphId
+            };
+        }
+
+        if (kg.KnowledgeType.IsEqualTo(KnowledgeBaseType.Taxonomy))
+        {
+            return new TaxonomyKnowledgeSearchOptions
+            {
+                DbProvider = request?.DbProvider,
+                Limit = request?.Limit ?? 5,
+                Confidence = request?.Confidence ?? 0.5f,
+                SearchParam = searchParam,
+                SearchArguments = request?.SearchArguments,
+                DataProviders = request?.DataProviders,
+                MaxNgram = request?.MaxNgram
+            };
+        }
+
+        return new KnowledgeExecuteOptions
+        {
+            DbProvider = request?.DbProvider,
+            Fields = request?.Fields,
+            FilterGroups = request?.FilterGroups,
+            Limit = request?.Limit ?? 5,
+            Confidence = request?.Confidence ?? 0.5f,
+            WithVector = request?.WithVector ?? false,
+            SearchParam = searchParam,
+            SearchArguments = request?.SearchArguments
+        };
Evidence
PR Compliance ID 1 requires defensive copies when storing/returning externally-origin collections.
The new BuildSearchOptions method passes request-owned collections/dictionaries through without
copying (Fields, FilterGroups, SearchArguments, DataProviders).

src/Infrastructure/BotSharp.OpenAPI/Controllers/KnowledgeBase/KnowledgeBaseController.cs[395-434]
Best Practice: Learned patterns

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
`BuildSearchOptions` propagates request-owned collections/dictionaries by reference, risking shared mutable state.

## Issue Context
The API request model (`KnowledgeExecuteRequest`) contains mutable collections (`Fields`, `FilterGroups`, `SearchArguments`, `DataProviders`). These should be copied before being stored/returned in options passed downstream.

## Fix Focus Areas
- src/Infrastructure/BotSharp.OpenAPI/Controllers/KnowledgeBase/KnowledgeBaseController.cs[395-434]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


2. RecoverCollectionFromSnapshot missing file guard 📘 Rule violation ☼ Reliability
Description
RecoverCollectionFromSnapshot uses snapshotFile.FileName and reads file content without guarding
snapshotFile for null/empty, risking null dereference and unexpected exceptions at the API
boundary. This should return a safe fallback (e.g., false) on invalid input.
Code

src/Infrastructure/BotSharp.OpenAPI/Controllers/KnowledgeBase/KnowledgeBaseController.cs[R339-351]

+    public async Task<bool> RecoverCollectionFromSnapshot([FromRoute] string collection, IFormFile snapshotFile, [FromForm] string knowledgeType, [FromForm] string? dbProvider = null)
    {
+        var kg = _services.GetServices<IKnowledgeService>()
+                          .FirstOrDefault(x => x.KnowledgeType.IsEqualTo(knowledgeType));
+
+        if (kg == null)
+        {
+            return false;
+        }
+
        var fileName = snapshotFile.FileName;
        var binary = FileUtility.BuildBinaryDataFromFile(snapshotFile);
-        var done = await _knowledgeService.RecoverVectorCollectionFromSnapshot(collection, fileName, binary);
+        var done = await kg.RecoverCollectionFromSnapshot(collection, fileName, binary, new KnowledgeSnapshotOptions { DbProvider = dbProvider });
Evidence
PR Compliance ID 2 requires explicit null/empty guards at API boundaries. The new endpoint reads
snapshotFile directly without validating it first.

src/Infrastructure/BotSharp.OpenAPI/Controllers/KnowledgeBase/KnowledgeBaseController.cs[339-351]
Best Practice: Learned patterns

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The snapshot recovery endpoint assumes `snapshotFile` is non-null and non-empty.

## Issue Context
At API boundaries, missing/malformed multipart form data can result in `snapshotFile` being null or empty.

## Fix Focus Areas
- src/Infrastructure/BotSharp.OpenAPI/Controllers/KnowledgeBase/KnowledgeBaseController.cs[339-351]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


3. UploadKnowledgeFiles lacks null/empty guards 📘 Rule violation ☼ Reliability
Description
Multiple file endpoints dereference [FromBody] request objects (and their collections like
Files) without guarding for null/empty, risking null dereferences or empty-sequence failures at
the API boundary. These should return safe fallbacks (e.g., empty response/false) when inputs are
invalid.
Code

src/Infrastructure/BotSharp.OpenAPI/Controllers/KnowledgeBase/KnowledgeBaseController.File.cs[R17-75]

+    [HttpPost("/knowledge/collection/{collection}/file/upload")]
+    public async Task<UploadKnowledgeResponse> UploadKnowledgeFiles([FromRoute] string collection, [FromBody] KnowledgeUploadRequest request)
+    {
+        var fileOrchestrator = GetKnowledgeFileOrchestrator(request.FileOrchestrator);
+        var response = await fileOrchestrator.UploadFilesToKnowledge(collection, request.Files, request.Options);
+        return response;
+    }
+
+    [HttpPost("/knowledge/collection/{collection}/file/form")]
+    public async Task<UploadKnowledgeResponse> UploadKnowledgeFiles(
+        [FromRoute] string collection,
+        [FromForm] IEnumerable<IFormFile> files,
+        [FromForm] string? orchestrator = null,
+        [FromForm] KnowledgeFileHandleOptions? options = null)
+    {
+        if (files.IsNullOrEmpty())
+        {
+            return new UploadKnowledgeResponse();
+        }
+
+        var docs = new List<ExternalFileModel>();
+        foreach (var file in files)
+        {
+            var data = FileUtility.BuildFileDataFromFile(file);
+            docs.Add(new ExternalFileModel
+            {
+                FileName = file.FileName,
+                FileData = data
+            });
+        }
+
+        var fileOrchestrator = GetKnowledgeFileOrchestrator(orchestrator);
+        var response = await fileOrchestrator.UploadFilesToKnowledge(collection, docs, options);
+        return response;
+    }
+
+    [HttpDelete("/knowledge/collection/{collection}/file/{fileId}")]
+    public async Task<bool> DeleteKnowledgeFile([FromRoute] string collection, [FromRoute] Guid fileId, [FromQuery] KnowledgeFileRequest? request = null)
+    {
+        var fileOrchestrator = GetKnowledgeFileOrchestrator(request?.FileOrchestrator);
+        var options = !string.IsNullOrWhiteSpace(request?.DbProvider) ? new KnowledgeFileOptions { DbProvider = request.DbProvider } : null;
+        var response = await fileOrchestrator.DeleteKnowledgeFile(collection, fileId, options);
+        return response;
+    }
+
+    [HttpDelete("/knowledge/collection/{collection}/file")]
+    public async Task<bool> DeleteKnowledgeFiles([FromRoute] string collection, [FromBody] GetKnowledgeFilesRequest request)
+    {
+        var fileOrchestrator = GetKnowledgeFileOrchestrator(request.FileOrchestrator);
+        var response = await fileOrchestrator.DeleteKnowledgeFiles(collection, request);
+        return response;
+    }
+
+    [HttpPost("/knowledge/collection/{collection}/file/page")]
+    public async Task<PagedItems<KnowledgeFileViewModel>> GetPagedKnowledgeFiles([FromRoute] string collection, [FromBody] GetKnowledgeFilesRequest request)
+    {
+        var fileOrchestrator = GetKnowledgeFileOrchestrator(request.FileOrchestrator);
+        var data = await fileOrchestrator.GetPagedKnowledgeFiles(collection, request);
+
Evidence
PR Compliance ID 2 requires explicit null/empty checks for request bodies and collections at
integration boundaries. The new controller methods call request.FileOrchestrator, request.Files,
and pass request through without validating request/Files first.

src/Infrastructure/BotSharp.OpenAPI/Controllers/KnowledgeBase/KnowledgeBaseController.File.cs[17-75]
Best Practice: Learned patterns

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
File endpoints assume `[FromBody]` request and its properties are always non-null/non-empty.

## Issue Context
Model binding can produce null request bodies and null/empty collections, which should be handled explicitly with safe fallbacks.

## Fix Focus Areas
- src/Infrastructure/BotSharp.OpenAPI/Controllers/KnowledgeBase/KnowledgeBaseController.File.cs[17-75]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


View more (3)
4. SaveToKnowledgebase misses vectorDb guard 📘 Rule violation ☼ Reliability
Description
SaveToKnowledgebase calls GetVectorDb(knowledgebaseProvider) and then uses
vectorDb.Upsert(...) without verifying the DB instance is non-null, risking runtime null
dereference at an integration boundary. It should explicitly handle a missing/invalid provider (safe
fallback or clear exception).
Code

src/Plugins/BotSharp.Plugin.KnowledgeBase/Services/File/KnowledgeFileOrchestrator.cs[R436-447]

+    private async Task<IEnumerable<string>> SaveToKnowledgebase(string collectionName, string knowledgebaseProvider, IEnumerable<string> contents, Dictionary<string, VectorPayloadValue>? payload = null)
    {
        if (contents.IsNullOrEmpty())
        {
            return Enumerable.Empty<string>();
        }

        var dataIds = new List<string>();
-        var vectorDb = GetVectorDb();
+        var vectorDb = GetVectorDb(knowledgebaseProvider);
        var textEmbedding = await GetTextEmbedding(collectionName);

        for (int i = 0; i < contents.Count(); i++)
Evidence
PR Compliance ID 2 requires guarding provider responses/parsed results at integration boundaries.
The changed line assigns vectorDb from GetVectorDb(knowledgebaseProvider) but no null guard
exists before using vectorDb.

src/Plugins/BotSharp.Plugin.KnowledgeBase/Services/File/KnowledgeFileOrchestrator.cs[436-456]
Best Practice: Learned patterns

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
`vectorDb` may be null for an unknown/misconfigured `knowledgebaseProvider`, but the code uses it unconditionally.

## Issue Context
`GetVectorDb(provider)` can fail to resolve a provider; integration code should either return a safe fallback (e.g., no-op with error log) or fail fast with a clear exception.

## Fix Focus Areas
- src/Plugins/BotSharp.Plugin.KnowledgeBase/Services/File/KnowledgeFileOrchestrator.cs[436-456]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


5. Wrong embedding model used 🐞 Bug ≡ Correctness
Description
VectorKnowledgeBase.CreateCollection assigns VectorCollectionCreateOptions.Model =
options.LlmProvider instead of options.LlmModel, so collection creation can be configured with the
wrong embedding model. This can lead to collections being created with incorrect embedding settings
and downstream retrieval/embedding mismatches.
Code

src/Plugins/BotSharp.Plugin.KnowledgeBase/Services/Base/Vector/VectorKnowledgeBase.Collection.cs[R70-74]

+        created = await vectorDb.CreateCollection(collectionName, options: new()
+        {
+            Provider = options.LlmProvider,
+            Model = options.LlmProvider,
+            Dimension = options.EmbeddingDimension
Evidence
The method stores the correct model in the persisted config (TextEmbedding.Model = options.LlmModel)
but then passes the provider again as the runtime create option Model, which is inconsistent with
the API contract where provider and model are separate fields.

src/Plugins/BotSharp.Plugin.KnowledgeBase/Services/Base/Vector/VectorKnowledgeBase.Collection.cs[56-75]
src/Infrastructure/BotSharp.Abstraction/Knowledges/Options/CollectionCreateOptions.cs[3-8]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

### Issue description
`VectorKnowledgeBase.CreateCollection` passes the wrong value for `VectorCollectionCreateOptions.Model` (`LlmProvider` instead of `LlmModel`). This can misconfigure collection creation for vector DB providers that rely on `Model`.

### Issue Context
`CollectionCreateOptions` explicitly separates `LlmProvider` and `LlmModel`, and the code already uses `LlmModel` correctly when persisting `TextEmbedding` config.

### Fix Focus Areas
- src/Plugins/BotSharp.Plugin.KnowledgeBase/Services/Base/Vector/VectorKnowledgeBase.Collection.cs[70-75]
- src/Infrastructure/BotSharp.Abstraction/Knowledges/Options/CollectionCreateOptions.cs[3-8]

### Expected change
Set `Model = options.LlmModel` in the `vectorDb.CreateCollection` call.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


6. No default graph provider 🐞 Bug ≡ Correctness
Description
SementicGraphKnowledgeBase.GetGraphDb only matches the passed provider and has no fallback when
provider is null, so semantic-graph ExecuteQuery returns empty results when DbProvider is omitted.
The controller builds GraphKnowledgeSearchOptions with DbProvider = request?.DbProvider (nullable),
making this failure path reachable.
Code

src/Plugins/BotSharp.Plugin.KnowledgeBase/Services/Graph/SementicGraphKnowledgeBase.cs[R57-60]

+    private IGraphDb? GetGraphDb(string? provider = null)
+    {
+        var db = _services.GetServices<IGraphDb>().FirstOrDefault(x => x.Provider.IsEqualTo(provider));
+        return db;
Evidence
The controller treats DbProvider as optional for graph queries, but SementicGraphKnowledgeBase
requires it to be non-null to find a matching IGraphDb. Existing GraphKnowledgeService shows the
intended pattern: fall back to settings.GraphDb.Provider when provider is null.

src/Infrastructure/BotSharp.OpenAPI/Controllers/KnowledgeBase/KnowledgeBaseController.cs[395-407]
src/Plugins/BotSharp.Plugin.KnowledgeBase/Services/Graph/SementicGraphKnowledgeBase.cs[56-61]
src/Plugins/BotSharp.Plugin.KnowledgeBase/Graph/GraphKnowledgeService.cs[29-35]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

### Issue description
`SementicGraphKnowledgeBase.GetGraphDb` returns null when `provider` is null, but the API/controller allows `DbProvider` to be omitted, causing semantic-graph knowledge queries to return empty results.

### Issue Context
`GraphKnowledgeService` already demonstrates the correct behavior: default to `_settings.GraphDb.Provider` when provider is null.

### Fix Focus Areas
- src/Plugins/BotSharp.Plugin.KnowledgeBase/Services/Graph/SementicGraphKnowledgeBase.cs[56-61]
- src/Infrastructure/BotSharp.OpenAPI/Controllers/KnowledgeBase/KnowledgeBaseController.cs[395-407]
- src/Plugins/BotSharp.Plugin.KnowledgeBase/Graph/GraphKnowledgeService.cs[29-35]

### Expected change
Inject `KnowledgeBaseSettings` into `SementicGraphKnowledgeBase` and implement the same fallback logic as `GraphKnowledgeService` (or, alternatively, select the first registered `IGraphDb` when provider is null).

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools



Remediation recommended

7. GetKnowledgeFileOrchestrator defaults provider 📘 Rule violation ⚙ Maintainability
Description
GetKnowledgeFileOrchestrator silently substitutes provider ??= "botsharp-knowledge-file", which
can mask missing/incorrect configuration rather than failing fast. This can lead to debugging and
contract-mapping issues when the wrong orchestrator is selected.
Code

src/Infrastructure/BotSharp.OpenAPI/Controllers/KnowledgeBase/KnowledgeBaseController.File.cs[R95-100]

+    private IKnowledgeFileOrchestrator GetKnowledgeFileOrchestrator(string? provider)
+    {
+        provider ??= "botsharp-knowledge-file";
+        var found = _services.GetServices<IKnowledgeFileOrchestrator>().First(x => x.Provider.IsEqualTo(provider));
+        return found;
+    }
Evidence
PR Compliance ID 4 requires failing fast on misconfiguration instead of silently falling back to
defaults. The new method assigns a default provider string when none is supplied.

src/Infrastructure/BotSharp.OpenAPI/Controllers/KnowledgeBase/KnowledgeBaseController.File.cs[95-100]
Best Practice: Learned patterns

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
A missing orchestrator provider is silently replaced with a default string, which can hide misconfiguration.

## Issue Context
If the orchestrator provider is required for correct routing, prefer throwing a clear exception (or returning a 4xx) instead of defaulting.

## Fix Focus Areas
- src/Infrastructure/BotSharp.OpenAPI/Controllers/KnowledgeBase/KnowledgeBaseController.File.cs[95-100]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


8. Quadratic content enumeration 🐞 Bug ➹ Performance
Description
KnowledgeFileOrchestrator.SaveToKnowledgebase iterates IEnumerable<string> using
contents.Count() and contents.ElementAt(i) in a for-loop, repeatedly enumerating the sequence.
For non-indexable enumerables (and larger documents), this becomes O(n^2) and can also misbehave for
one-shot enumerables.
Code

src/Plugins/BotSharp.Plugin.KnowledgeBase/Services/File/KnowledgeFileOrchestrator.cs[447]

        for (int i = 0; i < contents.Count(); i++)
Evidence
The method signature accepts IEnumerable<string> contents and the loop uses LINQ Count/ElementAt,
which are linear for most IEnumerable implementations unless the underlying type is an IList/array.

src/Plugins/BotSharp.Plugin.KnowledgeBase/Services/File/KnowledgeFileOrchestrator.cs[436-470]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

### Issue description
`SaveToKnowledgebase` uses `Count()` and `ElementAt(i)` on `IEnumerable<string>`, causing repeated enumeration and potential O(n^2) runtime.

### Issue Context
This path is used when uploading/importing knowledge files and can be hit with large content lists.

### Fix Focus Areas
- src/Plugins/BotSharp.Plugin.KnowledgeBase/Services/File/KnowledgeFileOrchestrator.cs[436-470]

### Expected change
Convert once at the start:
- `var contentList = contents as IList<string> ?? contents.ToList();`
Then loop over `contentList.Count` and index directly (or use `foreach`).

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


9. KnowledgeService selection can throw 🐞 Bug ☼ Reliability
Description
KnowledgeHook.GetKnowledgeService uses First()/First(predicate) and exact string equality, which
throws when no IKnowledgeService is registered or when the requested knowledge type has no matching
service. This can crash knowledge retrieval with an unhandled InvalidOperationException for
misconfigured/unknown types.
Code

src/Plugins/BotSharp.Plugin.KnowledgeBase/Hooks/KnowledgeHook.cs[R101-108]

+    private IKnowledgeService GetKnowledgeService(string? type = null)
+    {
+        var kgs = _services.GetServices<IKnowledgeService>();
+        if (!string.IsNullOrWhiteSpace(type))
+        {
+            return kgs.First(x => x.KnowledgeType == type);
+        }
+        return kgs.First();
Evidence
Both kgs.First() and kgs.First(x => x.KnowledgeType == type) throw on empty/no-match; unlike
other call sites (e.g., controllers) this method does not use a safe selection pattern
(FirstOrDefault + handling) or case-insensitive comparison.

src/Plugins/BotSharp.Plugin.KnowledgeBase/Hooks/KnowledgeHook.cs[101-109]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

### Issue description
`KnowledgeHook.GetKnowledgeService` can throw when the requested knowledge type isn't registered (or no services are registered), causing unhandled exceptions during knowledge lookup.

### Issue Context
Knowledge types are stringly-typed; a mismatch in config/case/typo can trigger this.

### Fix Focus Areas
- src/Plugins/BotSharp.Plugin.KnowledgeBase/Hooks/KnowledgeHook.cs[101-109]

### Expected change
Use `FirstOrDefault` + validation, and prefer case-insensitive comparison (`IsEqualTo`) to match the controller pattern. Return a controlled fallback or skip that knowledge base when no matching service exists.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


Grey Divider

Qodo Logo

@iceljc iceljc marked this pull request as draft May 2, 2026 00:37
Comment on lines +395 to +434
private KnowledgeExecuteOptions BuildSearchOptions(IKnowledgeService kg, KnowledgeExecuteRequest? request)
{
var searchParam = request?.SearchParam?.ToDictionary(x => x.Key, x => x.Value?.ConvertToString());

if (kg.KnowledgeType.IsEqualTo(KnowledgeBaseType.SemanticGraph))
{
return new GraphKnowledgeSearchOptions
{
DbProvider = request?.DbProvider,
SearchParam = searchParam,
SearchArguments = request?.SearchArguments,
GraphId = request?.GraphId
};
}

if (kg.KnowledgeType.IsEqualTo(KnowledgeBaseType.Taxonomy))
{
return new TaxonomyKnowledgeSearchOptions
{
DbProvider = request?.DbProvider,
Limit = request?.Limit ?? 5,
Confidence = request?.Confidence ?? 0.5f,
SearchParam = searchParam,
SearchArguments = request?.SearchArguments,
DataProviders = request?.DataProviders,
MaxNgram = request?.MaxNgram
};
}

return new KnowledgeExecuteOptions
{
DbProvider = request?.DbProvider,
Fields = request?.Fields,
FilterGroups = request?.FilterGroups,
Limit = request?.Limit ?? 5,
Confidence = request?.Confidence ?? 0.5f,
WithVector = request?.WithVector ?? false,
SearchParam = searchParam,
SearchArguments = request?.SearchArguments
};
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.

Action required

1. buildsearchoptions reuses request collections 📘 Rule violation ⛨ Security

BuildSearchOptions assigns caller-provided collections/dictionaries (e.g., Fields,
FilterGroups, SearchArguments, DataProviders) directly onto option objects, allowing shared
mutable state between layers. This can let downstream mutations leak back into request objects and
across components.
Agent Prompt
## Issue description
`BuildSearchOptions` propagates request-owned collections/dictionaries by reference, risking shared mutable state.

## Issue Context
The API request model (`KnowledgeExecuteRequest`) contains mutable collections (`Fields`, `FilterGroups`, `SearchArguments`, `DataProviders`). These should be copied before being stored/returned in options passed downstream.

## Fix Focus Areas
- src/Infrastructure/BotSharp.OpenAPI/Controllers/KnowledgeBase/KnowledgeBaseController.cs[395-434]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

Comment on lines +339 to +351
public async Task<bool> RecoverCollectionFromSnapshot([FromRoute] string collection, IFormFile snapshotFile, [FromForm] string knowledgeType, [FromForm] string? dbProvider = null)
{
var kg = _services.GetServices<IKnowledgeService>()
.FirstOrDefault(x => x.KnowledgeType.IsEqualTo(knowledgeType));

if (kg == null)
{
return false;
}

var fileName = snapshotFile.FileName;
var binary = FileUtility.BuildBinaryDataFromFile(snapshotFile);
var done = await _knowledgeService.RecoverVectorCollectionFromSnapshot(collection, fileName, binary);
var done = await kg.RecoverCollectionFromSnapshot(collection, fileName, binary, new KnowledgeSnapshotOptions { DbProvider = dbProvider });
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.

Action required

2. recovercollectionfromsnapshot missing file guard 📘 Rule violation ☼ Reliability

RecoverCollectionFromSnapshot uses snapshotFile.FileName and reads file content without guarding
snapshotFile for null/empty, risking null dereference and unexpected exceptions at the API
boundary. This should return a safe fallback (e.g., false) on invalid input.
Agent Prompt
## Issue description
The snapshot recovery endpoint assumes `snapshotFile` is non-null and non-empty.

## Issue Context
At API boundaries, missing/malformed multipart form data can result in `snapshotFile` being null or empty.

## Fix Focus Areas
- src/Infrastructure/BotSharp.OpenAPI/Controllers/KnowledgeBase/KnowledgeBaseController.cs[339-351]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

Comment on lines +17 to +75
[HttpPost("/knowledge/collection/{collection}/file/upload")]
public async Task<UploadKnowledgeResponse> UploadKnowledgeFiles([FromRoute] string collection, [FromBody] KnowledgeUploadRequest request)
{
var fileOrchestrator = GetKnowledgeFileOrchestrator(request.FileOrchestrator);
var response = await fileOrchestrator.UploadFilesToKnowledge(collection, request.Files, request.Options);
return response;
}

[HttpPost("/knowledge/collection/{collection}/file/form")]
public async Task<UploadKnowledgeResponse> UploadKnowledgeFiles(
[FromRoute] string collection,
[FromForm] IEnumerable<IFormFile> files,
[FromForm] string? orchestrator = null,
[FromForm] KnowledgeFileHandleOptions? options = null)
{
if (files.IsNullOrEmpty())
{
return new UploadKnowledgeResponse();
}

var docs = new List<ExternalFileModel>();
foreach (var file in files)
{
var data = FileUtility.BuildFileDataFromFile(file);
docs.Add(new ExternalFileModel
{
FileName = file.FileName,
FileData = data
});
}

var fileOrchestrator = GetKnowledgeFileOrchestrator(orchestrator);
var response = await fileOrchestrator.UploadFilesToKnowledge(collection, docs, options);
return response;
}

[HttpDelete("/knowledge/collection/{collection}/file/{fileId}")]
public async Task<bool> DeleteKnowledgeFile([FromRoute] string collection, [FromRoute] Guid fileId, [FromQuery] KnowledgeFileRequest? request = null)
{
var fileOrchestrator = GetKnowledgeFileOrchestrator(request?.FileOrchestrator);
var options = !string.IsNullOrWhiteSpace(request?.DbProvider) ? new KnowledgeFileOptions { DbProvider = request.DbProvider } : null;
var response = await fileOrchestrator.DeleteKnowledgeFile(collection, fileId, options);
return response;
}

[HttpDelete("/knowledge/collection/{collection}/file")]
public async Task<bool> DeleteKnowledgeFiles([FromRoute] string collection, [FromBody] GetKnowledgeFilesRequest request)
{
var fileOrchestrator = GetKnowledgeFileOrchestrator(request.FileOrchestrator);
var response = await fileOrchestrator.DeleteKnowledgeFiles(collection, request);
return response;
}

[HttpPost("/knowledge/collection/{collection}/file/page")]
public async Task<PagedItems<KnowledgeFileViewModel>> GetPagedKnowledgeFiles([FromRoute] string collection, [FromBody] GetKnowledgeFilesRequest request)
{
var fileOrchestrator = GetKnowledgeFileOrchestrator(request.FileOrchestrator);
var data = await fileOrchestrator.GetPagedKnowledgeFiles(collection, request);

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.

Action required

3. uploadknowledgefiles lacks null/empty guards 📘 Rule violation ☼ Reliability

Multiple file endpoints dereference [FromBody] request objects (and their collections like
Files) without guarding for null/empty, risking null dereferences or empty-sequence failures at
the API boundary. These should return safe fallbacks (e.g., empty response/false) when inputs are
invalid.
Agent Prompt
## Issue description
File endpoints assume `[FromBody]` request and its properties are always non-null/non-empty.

## Issue Context
Model binding can produce null request bodies and null/empty collections, which should be handled explicitly with safe fallbacks.

## Fix Focus Areas
- src/Infrastructure/BotSharp.OpenAPI/Controllers/KnowledgeBase/KnowledgeBaseController.File.cs[17-75]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

Comment on lines +436 to 447
private async Task<IEnumerable<string>> SaveToKnowledgebase(string collectionName, string knowledgebaseProvider, IEnumerable<string> contents, Dictionary<string, VectorPayloadValue>? payload = null)
{
if (contents.IsNullOrEmpty())
{
return Enumerable.Empty<string>();
}

var dataIds = new List<string>();
var vectorDb = GetVectorDb();
var vectorDb = GetVectorDb(knowledgebaseProvider);
var textEmbedding = await GetTextEmbedding(collectionName);

for (int i = 0; i < contents.Count(); i++)
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.

Action required

4. savetoknowledgebase misses vectordb guard 📘 Rule violation ☼ Reliability

SaveToKnowledgebase calls GetVectorDb(knowledgebaseProvider) and then uses
vectorDb.Upsert(...) without verifying the DB instance is non-null, risking runtime null
dereference at an integration boundary. It should explicitly handle a missing/invalid provider (safe
fallback or clear exception).
Agent Prompt
## Issue description
`vectorDb` may be null for an unknown/misconfigured `knowledgebaseProvider`, but the code uses it unconditionally.

## Issue Context
`GetVectorDb(provider)` can fail to resolve a provider; integration code should either return a safe fallback (e.g., no-op with error log) or fail fast with a clear exception.

## Fix Focus Areas
- src/Plugins/BotSharp.Plugin.KnowledgeBase/Services/File/KnowledgeFileOrchestrator.cs[436-456]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

Comment on lines +70 to +74
created = await vectorDb.CreateCollection(collectionName, options: new()
{
Provider = options.LlmProvider,
Model = options.LlmProvider,
Dimension = options.EmbeddingDimension
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.

Action required

5. Wrong embedding model used 🐞 Bug ≡ Correctness

VectorKnowledgeBase.CreateCollection assigns VectorCollectionCreateOptions.Model =
options.LlmProvider instead of options.LlmModel, so collection creation can be configured with the
wrong embedding model. This can lead to collections being created with incorrect embedding settings
and downstream retrieval/embedding mismatches.
Agent Prompt
### Issue description
`VectorKnowledgeBase.CreateCollection` passes the wrong value for `VectorCollectionCreateOptions.Model` (`LlmProvider` instead of `LlmModel`). This can misconfigure collection creation for vector DB providers that rely on `Model`.

### Issue Context
`CollectionCreateOptions` explicitly separates `LlmProvider` and `LlmModel`, and the code already uses `LlmModel` correctly when persisting `TextEmbedding` config.

### Fix Focus Areas
- src/Plugins/BotSharp.Plugin.KnowledgeBase/Services/Base/Vector/VectorKnowledgeBase.Collection.cs[70-75]
- src/Infrastructure/BotSharp.Abstraction/Knowledges/Options/CollectionCreateOptions.cs[3-8]

### Expected change
Set `Model = options.LlmModel` in the `vectorDb.CreateCollection` call.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

Comment on lines +57 to +60
private IGraphDb? GetGraphDb(string? provider = null)
{
var db = _services.GetServices<IGraphDb>().FirstOrDefault(x => x.Provider.IsEqualTo(provider));
return db;
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.

Action required

6. No default graph provider 🐞 Bug ≡ Correctness

SementicGraphKnowledgeBase.GetGraphDb only matches the passed provider and has no fallback when
provider is null, so semantic-graph ExecuteQuery returns empty results when DbProvider is omitted.
The controller builds GraphKnowledgeSearchOptions with DbProvider = request?.DbProvider (nullable),
making this failure path reachable.
Agent Prompt
### Issue description
`SementicGraphKnowledgeBase.GetGraphDb` returns null when `provider` is null, but the API/controller allows `DbProvider` to be omitted, causing semantic-graph knowledge queries to return empty results.

### Issue Context
`GraphKnowledgeService` already demonstrates the correct behavior: default to `_settings.GraphDb.Provider` when provider is null.

### Fix Focus Areas
- src/Plugins/BotSharp.Plugin.KnowledgeBase/Services/Graph/SementicGraphKnowledgeBase.cs[56-61]
- src/Infrastructure/BotSharp.OpenAPI/Controllers/KnowledgeBase/KnowledgeBaseController.cs[395-407]
- src/Plugins/BotSharp.Plugin.KnowledgeBase/Graph/GraphKnowledgeService.cs[29-35]

### Expected change
Inject `KnowledgeBaseSettings` into `SementicGraphKnowledgeBase` and implement the same fallback logic as `GraphKnowledgeService` (or, alternatively, select the first registered `IGraphDb` when provider is null).

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

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.

1 participant