Repository navigation
feat: support SelectFields override in DocEngine for KG-specific queries - #15684
Conversation
ES and Infinity engines now respect SearchRequest.SelectFields, allowing callers to specify output columns for KG entity/relation/ community queries instead of using the default chunk columns. Co-Authored-By: Claude Opus 4.8 <[email protected]>
📝 WalkthroughWalkthroughThis PR adds SelectFields override support to both Elasticsearch and Infinity search engines. When a caller provides ChangesField Selection Override
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. 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/engine/elasticsearch/kg_test.go (1)
52-56: ⚡ Quick winConsider verifying that results were returned to avoid false positives.
The test iterates over
result.Chunks(line 65), but if the search returns zero results, the validation loop never executes and the test silently passes. This could mask issues where SelectFields filtering isn't working.✅ Suggested improvement
result, err := engine.Search(context.Background(), req) if err != nil { t.Fatalf("search failed: %v", err) } + if len(result.Chunks) == 0 { + t.Skip("No KG entity data found in test environment; skipping field validation") + } // Verify returned chunks contain only allowed fields🤖 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/engine/elasticsearch/kg_test.go` around lines 52 - 56, The test calls engine.Search(ctx, req) and then loops over result.Chunks but never asserts any results; add an explicit check after the search (e.g., verify len(result.Chunks) > 0) and call t.Fatalf or t.Fatalf-like assertion if zero so the test fails when no results are returned before iterating; update the test in kg_test.go around the engine.Search/result.Chunks usage to ensure SelectFields filtering is actually exercised.
🤖 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/engine/elasticsearch/kg_test.go`:
- Around line 52-56: The test calls engine.Search(ctx, req) and then loops over
result.Chunks but never asserts any results; add an explicit check after the
search (e.g., verify len(result.Chunks) > 0) and call t.Fatalf or t.Fatalf-like
assertion if zero so the test fails when no results are returned before
iterating; update the test in kg_test.go around the engine.Search/result.Chunks
usage to ensure SelectFields filtering is actually exercised.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 9f4f277e-4112-42bd-a76d-fe9971e20679
📒 Files selected for processing (3)
internal/engine/elasticsearch/chunk.gointernal/engine/elasticsearch/kg_test.gointernal/engine/infinity/chunk.go
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #15684 +/- ##
=======================================
Coverage 93.16% 93.16%
=======================================
Files 10 10
Lines 717 717
Branches 118 118
=======================================
Hits 668 668
Misses 29 29
Partials 20 20 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
## Summary Knowledge Graph search functions for entity, relation, community report, and type-samples retrieval. Uses DocEngine.SelectFields (PR #15684) for KG-specific fields. ### Functions | Function | Description | |----------|-------------| | `SearchKGEntities` | Hybrid search over KG entities (dense + text + fusion) | | `SearchKGEntitiesByTypes` | Entity search filtered by `entity_type_kwd` | | `SearchKGRelations` | Hybrid search over KG relations | | `SearchKGCommunityReports` | Community report search by entity names | | `SearchKGTypeSamples` | Type→entities mapping for query_rewrite | ### Internal helpers | Helper | Description | |--------|-------------| | `buildHybridExpr` | Shared dense+text+fusion expression construction | | `buildKGDenseExpr` | Wraps `Embed()` call for vector search | | `Parse*` | Convert raw chunks to typed structs | ### Testing 35 tests (pure function + mock integration) Co-Authored-By: Claude Opus 4.8 <[email protected]> --------- Co-authored-by: Claude Opus 4.8 <[email protected]>
Summary
Both ES and Infinity engines now respect
SearchRequest.SelectFields, allowing callers to specify output columns for KG entity/relation/community queries instead of the default chunk columns.Changes
internal/engine/elasticsearch/chunk.go: AddedSelectFieldsoverride after defaultoutputColumnsinternal/engine/infinity/chunk.go: AddedSelectFieldsoverride after defaultoutputColumnsinternal/engine/elasticsearch/kg_test.go(new): Integration test (skipped unlessES_TEST=1)Usage