Skip to content

Implement retrieval_test in GO - #14231

Merged
yuzhichang merged 3 commits into
infiniflow:mainfrom
qinling0210:go_infinity_search
Apr 24, 2026
Merged

yuzhichang merged 3 commits into
infiniflow:mainfrom
qinling0210:go_infinity_search

Conversation

@qinling0210

@qinling0210 qinling0210 commented Apr 20, 2026 •

Copy link
Copy Markdown
Contributor

What problem does this PR solve?

Implement retrieval_test in GO

Type of change

  • Refactoring

@coderabbitai

coderabbitai Bot commented Apr 20, 2026 •

Copy link
Copy Markdown
Contributor

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Convert search APIs to strongly typed SearchRequest/SearchResult, implement a RetrievalService with hybrid retrieval and reranking, add tenant-aware model resolution and chat/rerank factory support, introduce LLM-driven metadata filtering and prompt rendering, add multi-message chat driver support, and update engines, utilities, and many service/DAO layers accordingly.

Changes

Cohort / File(s) Summary
Search Types & Engine API
internal/engine/types/types.go, internal/engine/engine.go, internal/engine/global.go
Introduce typed SearchRequest/SearchResult, add Order/Match expr types, change DocEngine.Search signature, remove old exported aliases, store engine type and add GetEngineType().
Infinity Engine
internal/engine/infinity/... (search.go, get.go, common.go, dataset.go)
Rewrite Infinity search to accept typed requests, rebuild filter serialization and result conversion, add exported GetFields and helpers, adjust keyword-field detection and filter formatting, and inline field mapping.
Elasticsearch Engine
internal/engine/elasticsearch/search.go, internal/engine/elasticsearch/get.go
Migrate to typed search API, remove legacy dispatcher, unify pagination (Offset/Limit), simplify filter/query handling, and adapt GetChunk to use typed SearchRequest/SearchResult.
Retrieval & Reranking Pipeline
internal/service/nlp/retrieval.go, internal/service/nlp/reranker.go, internal/service/nlp/query_builder.go
Add RetrievalService with hybrid/fulltext flows, Search wrapper, retrieval-by-children aggregation; refactor reranker to operate on chunk maps plus explicit total and rankFeature fusion; adjust tokenization/synonym behavior.
Chunk Service & API
internal/service/chunk.go, api/apps/chunk_app.py
Rewrite RetrievalTest to use new Filter format, metadata-filtering, cross-language/keyword extraction, tenant rerank resolution, call new RetrievalService, remove vector from returned chunks, and ensure response ranks includes explicit total.
Metadata Filtering & Tagging
internal/service/metadata_filter.go, internal/service/metadata.go, internal/service/tag.go
Add LLM-driven meta-filter generation (auto/semi/manual), metadata flattening/merge helpers, tag aggregation with Redis caching, and LabelQuestion orchestration.
Model Provider / Factories / Siliconflow
internal/service/model_service.go, internal/service/models/factory.go, internal/service/models/siliconflow_model.go, conf/models/siliconflow.json
Prefer TenantLLM.APIBase for apiBase, implement GetChat/GetRerank/GetEmbedding resolution, register chat/rerank factory registries and Create*Model helpers, and add Siliconflow provider chat/rerank model + config.
Model Driver Multi-message Chat
internal/entity/models/types.go, internal/entity/models/*.go
Add Message type and ChatWithMessages API; implement for ZhipuAI and add not-implemented stubs for other drivers (DeepSeek/Minimax/Moonshot/Dummy).
Prompt Loading & Generation
internal/service/load_prompt.go, internal/service/generator.go
Add prompt discovery/loading with caching and template rendering (simple filters), plus LLM-backed KeywordExtraction and CrossLanguages helpers.
Supporting Types & Utilities
internal/common/constants.go, internal/entity/types.go, internal/entity/kb.go, internal/utility/convert.go, internal/logger/logger.go, internal/tokenizer/tokenizer.go
Add pagerank/tag constants, ModelCredentials, KB TenantEmbdID, numeric/float helpers, IsDebugEnabled, and engine-aware tokenizer bypass for Infinity.
DAO & Services
internal/dao/tenant_llm.go, internal/service/search.go
Add TenantLLM lookups (GetByID, GetByTenantNameAndType) and lookup helpers; implement model resolution helpers and add SearchService.GetDetail.
Misc & Devtools
internal/cli/user_parser.go, go.mod, rag/*, internal/entity/models/*
Minor CLI comment tweaks, promote xxhash dep and update Infinity SDK replace, small Python/Go rerank debug logs, and add provider ChatWithMessages stubs.

Sequence Diagram(s)

sequenceDiagram
    participant Client as Client
    participant ChunkSvc as ChunkService
    participant MetaSvc as MetadataService
    participant LLM as LLMModel
    participant NLPR as RetrievalService
    participant Engine as DocEngine
    participant Rerank as RerankModel

    Client->>ChunkSvc: RetrievalTest(request)
    ChunkSvc->>MetaSvc: ApplyMetaDataFilter(question, meta)
    MetaSvc->>LLM: GenMetaFilter(prompt)
    LLM-->>MetaSvc: filter conditions
    MetaSvc-->>ChunkSvc: filtered docIDs

    ChunkSvc->>LLM: KeywordExtraction / CrossLanguages
    LLM-->>ChunkSvc: keywords / translated query

    ChunkSvc->>NLPR: Retrieval(SearchRequest)
    NLPR->>Engine: Search(*types.SearchRequest)
    Engine-->>NLPR: SearchResult (chunks, total)

    NLPR->>Rerank: Rerank(chunks, total, rankFeature)
    Rerank-->>NLPR: similarity scores
    NLPR->>NLPR: apply scores, sort, paginate
    NLPR-->>ChunkSvc: RetrievalResult(chunks, docAggs)
    ChunkSvc-->>Client: RetrievalTestResponse(ranks with total, labels)
Loading

Estimated code review effort

🎯 5 (Critical) | ⏱️ ~120 minutes

Possibly related PRs

Poem

🐰 I nibble prompts and hop through typed requests,

Filters hum and children cluster, rerank sorts the best,
LLM whispers constraints, engines fetch the scene,
Parents gather children, highlights glow between,
A joyful rabbit hops—search tuned and fully dressed!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main objective of the PR, which is implementing retrieval_test functionality in Go.
Description check ✅ Passed The description follows the required template structure with both 'What problem does this PR solve?' and 'Type of change' sections appropriately filled out.
Docstring Coverage ✅ Passed Docstring coverage is 89.01% 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.

@qinling0210
qinling0210 force-pushed the go_infinity_search branch 2 times, most recently from 7602b85 to c0bc1cb Compare April 23, 2026 12:55
@qinling0210 qinling0210 changed the title 0420 Implement retrieval_test in GO Apr 23, 2026
@qinling0210 qinling0210 self-assigned this Apr 23, 2026