Repository navigation
feat(dao): add shared ResolveModelContentLength helper - #18106
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughAdded ChangesModel context resolution
Estimated code review effort: 3 (Moderate) | ~20 minutes Suggested labels: Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
internal/dao/model_context.go (1)
40-55: 🚀 Performance & Scalability | 🔵 Trivial | ⚡ Quick winParse composite references before the tenant-model query.
A composite reference contains
@. It cannot be a tenant-model UUID under this API contract. The current order performsGetByIDbefore the catalog lookup.Resolve the composite form first. This removes one database query from each composite-reference resolution.
Proposed change
- // 1. Tenant model UUID: read content_length from its provider catalog row. - if db != nil && modelRef != "" { + // 1. Composite reference: look up the provider catalog. + if pureName, _, providerName, ok := splitCompositeModelRef(modelRef); ok { + if mdl, err := GetModelProviderManager().GetModelByName(providerName, pureName); err == nil && mdl.ContentLength != nil { + return *mdl.ContentLength + } + } + // 2. Tenant model UUID: read content_length from its provider catalog row. + if db != nil && modelRef != "" { if obj, err := NewTenantModelDAO().GetByID(ctx, db, modelRef); err == nil && obj != nil && obj.Status == "active" { // ... } } - // 2. Composite "model@provider" reference: look up the provider catalog. - if pureName, _, providerName, ok := splitCompositeModelRef(modelRef); ok { - if mdl, err := GetModelProviderManager().GetModelByName(providerName, pureName); err == nil && mdl.ContentLength != nil { - return *mdl.ContentLength - } - }🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@internal/dao/model_context.go` around lines 40 - 55, Update the model content-length resolution flow to call splitCompositeModelRef before the tenant-model lookup. For valid composite references, resolve via GetModelProviderManager().GetModelByName and return its ContentLength without invoking NewTenantModelDAO().GetByID; only perform the tenant-model query for non-composite references.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@internal/dao/model_context.go`:
- Around line 40-55: Update the model content-length resolution flow to call
splitCompositeModelRef before the tenant-model lookup. For valid composite
references, resolve via GetModelProviderManager().GetModelByName and return its
ContentLength without invoking NewTenantModelDAO().GetByID; only perform the
tenant-model query for non-composite references.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 4dd9f6ab-7054-4164-a372-958f293024f4
📒 Files selected for processing (2)
internal/dao/model_context.gointernal/dao/model_context_test.go
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@internal/dao/model_context_test.go`:
- Around line 46-57: Strengthen TestResolveModelContentLength_TooManyParts so it
directly verifies excessive-separator rejection instead of relying on the
unknown catalog input. Use a known catalog model prefix with an extra separator
in the no-fallback assertion, or add an explicit assertion that
splitCompositeModelRef rejects "a@b@c@d", while preserving the existing fallback
expectations.
🪄 Autofix
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: f6abb33c-611f-40f9-80f4-2bde3972e745
📒 Files selected for processing (1)
internal/dao/model_context_test.go
Resolve a chat model's context window (content_length) from either a tenant_model UUID or a composite model@provider reference, with an optional driver+modelName catalog fallback for the no-database path. The agent LLM component and the ingestion Extractor both need this lookup but cannot import each other or internal/service (import cycles), so each currently carries its own copy. This is the shared implementation; follow-up PRs switch those callers onto it. Adds unit tests for the composite, driver+modelName fallback, tenant UUID, inactive-row, and unknown-reference paths.
Add coverage for the model@instance@provider reference form and document that references with more than two "@" separators fall through to the driver+modelName fallback (or 0), matching splitCompositeModelRef.
add6eee to
824dad7
Compare
|
Note GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer. |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@internal/dao/model_context.go`:
- Around line 41-48: Update the model resolution flow around the tenant-model
lookup to parse valid composite model references such as “model@provider” before
querying the database. Resolve catalog-backed composite references directly, and
only execute NewTenantModelDAO().GetByID for non-composite references while
preserving the existing tenant-model status and provider checks.
🪄 Autofix
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: db75aa8a-92f0-4fbb-95bd-cccaa5f7f799
📒 Files selected for processing (2)
internal/dao/model_context.gointernal/dao/model_context_test.go
🚧 Files skipped from review as they are similar to previous changes (1)
- internal/dao/model_context_test.go
Resolve 'model@provider' / 'model@instance@provider' references directly from the provider catalog before querying the database — a composite ref cannot be a tenant-model UUID, so the catalog-only path needs no DB. Harden TestResolveModelContentLength_TooManyParts to use a known catalog model with an extra separator and assert splitCompositeModelRef rejects excessive separators, so a parser regression fails loudly.
review fixes Resolve composite refs before the tenant-model lookup and harden the too-many-parts test, matching the updated infiniflow#18106 helper so the stack stays consistent until infiniflow#18106 merges.
review fixes Resolve composite refs before the tenant-model lookup and harden the too-many-parts test, matching the updated infiniflow#18106 helper so the stack stays consistent until infiniflow#18106 merges.
Summary
Add a shared
dao.ResolveModelContentLengththat resolves a chat model's context window (content_length) from atenant_modelUUID or a compositemodel@providerreference, with an optionaldriver + modelNamecatalog fallback for the no-database path.Why
The agent LLM component (PR #18093) and the ingestion Extractor (PR #18095) both need this lookup, but they cannot import each other or
internal/service(import cycles). Each previously carried an identical private copy; both callers now use this shared helper instead.Changes
internal/dao/model_context.go:ResolveModelContentLength(ctx, db, modelRef, driver, modelName) intmodel@provider/model@instance@provider→ provider catalogdriver + modelNamefallback (no database needed)internal/dao/model_context_test.go: covers composite, driver+modelName fallback, tenant UUID, inactive row, unknown and empty references.Testing
bash build.sh --test ./internal/dao/...passes.main(a0e091e75).Known limitations (follow-up)
The resolver reads
content_lengthfrom the provider catalog only. Python resolves a tenant model's context asmodel_extra.get("max_tokens") or 8192(and the composite path honors the per-modelmax_tokensoverride first), so a per-modelmax_tokensoverride intenant_model.extra— common for custom/local models — is currently ignored: such models resolve to 0 and callers fall back to the 8192 budget. A follow-up PR will honorTenantModel.Extra["max_tokens"](mirroringtenantModelExtraininternal/ingestion/component/dispatch_model.go).