Skip to content

feat: support SelectFields override in DocEngine for KG-specific queries - #15684

Merged
yingfeng merged 1 commit into
infiniflow:mainfrom
xugangqiang:feat/go-doc-engine-kg
Jun 5, 2026
Merged

yingfeng merged 1 commit into
infiniflow:mainfrom
xugangqiang:feat/go-doc-engine-kg

Conversation

@xugangqiang

Copy link
Copy Markdown
Contributor

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: Added SelectFields override after default outputColumns
  • internal/engine/infinity/chunk.go: Added SelectFields override after default outputColumns
  • internal/engine/elasticsearch/kg_test.go (new): Integration test (skipped unless ES_TEST=1)

Usage

result, err := docEngine.Search(ctx, \&types.SearchRequest{
    KbIDs:        kbIDs,
    SelectFields: []string{entity_kwd, entity_type_kwd, rank_flt, n_hop_with_weight},
    Filter:       map[string]interface{}{knowledge_graph_kwd: entity},
})

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]>
@xugangqiang xugangqiang added the ci Continue Integration label Jun 5, 2026
@coderabbitai

coderabbitai Bot commented Jun 5, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

This PR adds SelectFields override support to both Elasticsearch and Infinity search engines. When a caller provides req.SelectFields, the engines now use those specified fields instead of computing default output columns based on index type. An integration test validates the Elasticsearch behavior with KG entity search.

Changes

Field Selection Override

Layer / File(s) Summary
Elasticsearch SelectFields override and integration test
internal/engine/elasticsearch/chunk.go, internal/engine/elasticsearch/kg_test.go
searchUnified checks req.SelectFields and overrides computed outputColumns when caller provides field selection. Integration test verifies KG search respects SelectFields constraint and only returns specified fields. Adds getTestConfig() helper for environment-driven ES configuration.
Infinity engine SelectFields override
internal/engine/infinity/chunk.go
(*infinityEngine).Search applies same override logic: when req.SelectFields is non-empty, replaces outputColumns with convertSelectFields(req.SelectFields) before query construction.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

A field selector's gentle hand,
Now guides both engines through the land,
Pick your columns, cast your spell—
Elasticsearch and Infinity serve them well! 🐇✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely summarizes the main feature: adding SelectFields override support to DocEngine for KG-specific queries, which aligns with the changeset's core objective.
Description check ✅ Passed The description includes a clear summary, lists all file changes with context, provides a practical usage example, but is missing the 'Type of change' checkbox from the template.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ 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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@xugangqiang
xugangqiang marked this pull request as ready for review June 5, 2026 02:01
@dosubot dosubot Bot added the size:S This PR changes 10-29 lines, ignoring generated files. label Jun 5, 2026

@coderabbitai coderabbitai Bot left a comment

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.

🧹 Nitpick comments (1)
internal/engine/elasticsearch/kg_test.go (1)

52-56: ⚡ Quick win

Consider 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

📥 Commits

Reviewing files that changed from the base of the PR and between 794c1f4 and 6ce94f0.

📒 Files selected for processing (3)
  • internal/engine/elasticsearch/chunk.go
  • internal/engine/elasticsearch/kg_test.go
  • internal/engine/infinity/chunk.go

@codecov

codecov Bot commented Jun 5, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.16%. Comparing base (98f2a2e) to head (6ce94f0).
⚠️ Report is 8 commits behind head on main.

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@yingfeng
yingfeng merged commit 3b1ae3f into infiniflow:main Jun 5, 2026
1 check passed
yingfeng pushed a commit that referenced this pull request Jun 5, 2026
## 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]>
@xugangqiang
xugangqiang deleted the feat/go-doc-engine-kg branch August 7, 2026 12:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci Continue Integration size:S This PR changes 10-29 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants