Skip to content

Conversation

@vidurkhanal
Copy link
Member

  • Extracted LanguageModel, RerankingModel, and EmbeddingModel structs and their error types from lib.rs into new files under models/.
  • Updated imports and usage throughout the codebase to reference the new models module.
  • Moved related trait definitions (GeneratesText, GeneratesObject, Reranks, ReranksStructuredData, Embeds) to their respective response generator modules.
  • Centralized AIProvider enum and its implementations in providers/mod.rs for better separation of concerns.
  • No functional changes; this is an internal code organization and modularization improvement.

- Extracted `LanguageModel`, `RerankingModel`, and `EmbeddingModel` structs and their error types from `lib.rs` into new files under `models/`.
- Updated imports and usage throughout the codebase to reference the new `models` module.
- Moved related trait definitions (`GeneratesText`, `GeneratesObject`, `Reranks`, `ReranksStructuredData`, `Embeds`) to their respective response generator modules.
- Centralized `AIProvider` enum and its implementations in `providers/mod.rs` for better separation of concerns.
- No functional changes; this is an internal code organization and modularization improvement.
@greptile-apps
Copy link
Contributor

greptile-apps bot commented Jan 22, 2026

Greptile Summary

Successfully refactored umem_ai crate by extracting model structs (LanguageModel, EmbeddingModel, RerankingModel) and their error types into a dedicated models/ module, and moved trait definitions (GeneratesText, GeneratesObject, Reranks, ReranksStructuredData, Embeds) to their respective response generator modules.

Key improvements:

  • Reduced lib.rs from ~250 lines to ~20 lines, improving discoverability
  • Created logical separation: models/ for data structures, providers/ for implementations, response_generators/ for traits
  • Centralized AIProvider enum in providers/mod.rs for better cohesion
  • All imports updated correctly across 16 files
  • No functional changes - purely organizational refactoring

The refactoring follows Rust module best practices and significantly improves code maintainability.

Confidence Score: 5/5

  • This PR is safe to merge with no risk
  • This is a pure refactoring with no behavioral changes. All code was moved (not rewritten), imports are correctly updated, and the module structure follows Rust conventions. The changes improve code organization without introducing any logic modifications.
  • No files require special attention

Important Files Changed

Filename Overview
crates/umem_ai/src/lib.rs Simplified to expose models module and re-export its contents; removed 226 lines of code that were moved to dedicated modules
crates/umem_ai/src/models/mod.rs New module file that organizes and re-exports language, embedding, and reranking model definitions
crates/umem_ai/src/models/language.rs Extracted LanguageModel struct and LanguageModelError from lib.rs with correct imports
crates/umem_ai/src/models/embedding.rs Extracted EmbeddingModel struct and EmbeddingModelError from lib.rs with correct imports
crates/umem_ai/src/models/reranking.rs Extracted RerankingModel struct and RerankingModelError from lib.rs with correct imports
crates/umem_ai/src/providers/mod.rs Centralized AIProvider enum and all its implementations (149 lines added), improving separation of concerns

Sequence Diagram

sequenceDiagram
    participant Client as Client Code
    participant ModelImpl as model_impl/
    participant Models as models/
    participant Providers as providers/
    participant ResponseGen as response_generators/
    
    Note over Models: New Module Structure
    Note over Models: language.rs, embedding.rs, reranking.rs
    
    Client->>ModelImpl: get_model()
    ModelImpl->>Models: LanguageModel::new()
    Models->>Providers: AIProvider enum
    Note over Providers: Centralized in providers/mod.rs
    
    Client->>ResponseGen: generate_text(request)
    ResponseGen->>Models: request.model (LanguageModel)
    Models->>Providers: model.provider (AIProvider)
    Providers->>Providers: do_generate_text()
    Note over Providers: Matches on provider type
    Providers-->>ResponseGen: GenerateTextResponse
    ResponseGen-->>Client: Result
    
    Note over ResponseGen: Traits moved to response_generators/
    Note over ResponseGen: GeneratesText, GeneratesObject, Embeds, Reranks, ReranksStructuredData
Loading

@vidurkhanal vidurkhanal enabled auto-merge January 22, 2026 06:17
@vidurkhanal vidurkhanal merged commit 4da6186 into main Jan 26, 2026
2 checks passed
@vidurkhanal vidurkhanal deleted the chore/umem-cleanup-and-modularization branch January 26, 2026 02:59
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.

3 participants