Skip to content

feat: configure similarity top-K in the VertexAiRagRetrieval tool - #1442

Open
pgentile wants to merge 1 commit into
google:mainfrom
pgentile:rag_retrieval_similarity_top_k
Open

pgentile wants to merge 1 commit into
google:mainfrom
pgentile:rag_retrieval_similarity_top_k

Conversation

@pgentile

@pgentile pgentile commented Aug 19, 2026 •

Copy link
Copy Markdown

Link to Issue or Description of Change

Problem:

Add support for the similarity top-K parameter in the VertexAiRagRetrieval tool

Solution:

New similarityTopK constructor parameter in the constructor of the VertexAiRagRetrieval class.

The similarity top-K is then added to the LLM request, when the model is a Gemini one and when the GOOGLE_GENAI_USE_VERTEXAI env var is enabled. Otherwise, the similarity top-K parameter is transmitted to the retrieveContexts method.

Testing Plan

Updates of the VertexAiRagRetrievalTest unit test.

Unit Tests:

  • I have added or updated unit tests for my change.
  • All unit tests pass locally.
[INFO] +-- com.google.adk.tools.retrieval.VertexAiRagRetrievalTest
[INFO] | +-- [OK] processLlmRequest_otherModel_doNotAddVertexRagStoreToConfig - 1.298 ss
[INFO] | +-- [OK] processLlmRequest_gemini2Model_addVertexRagStoreToConfig - 0.006 ss

...

[INFO] +-- com.google.adk.tools.retrieval.VertexAiRagRetrievalTest
[INFO] | +-- [OK] processLlmRequest_otherModel_doNotAddVertexRagStoreToConfig - 0.084 ss
[INFO] | +-- [OK] processLlmRequest_gemini2Model_addVertexRagStoreToConfig - 0.001 ss
[INFO] | +-- [OK] runAsync_withResults_returnsContexts - 0.190 ss
[INFO] | +-- [OK] runAsync_noResults_returnsNoResultFoundMessage - 0.003 ss
[INFO] | +-- [OK] processLlmRequest_gemini2Model_withoutSimilarityTopK_addVertexRagStoreToConfig - 0 ss

Manual End-to-End (E2E) Tests:

  • Use the tool new parameter in a production agent.
  • Check both code branches based on the GOOGLE_GENAI_USE_VERTEXAI env var.
  • Count retrieved chunks from the RAG corpus. The number of chunks must match the configured similarity top-K

Checklist

  • I have read the CONTRIBUTING.md document.
  • My pull request contains a single commit.
  • I have performed a self-review of my own code.
  • I have commented my code, particularly in hard-to-understand areas.
  • I have added tests that prove my fix is effective or that my feature works.
  • New and existing unit tests pass locally with my changes.
  • I have manually tested my changes end-to-end.
  • Any dependent changes have been merged and published in downstream modules.

Additional context

N/A

@pgentile
pgentile marked this pull request as ready for review August 19, 2026 15:07
@pgentile
pgentile force-pushed the rag_retrieval_similarity_top_k branch from 71cd444 to 2493cd1 Compare August 19, 2026 15:07
@hemasekhar-p hemasekhar-p self-assigned this Aug 21, 2026
@hemasekhar-p

Copy link
Copy Markdown
Contributor

Hi @pgentile, thank you for your contribution! We appreciate you taking the time to submit this pull request. Currently this PR is under review by our team we will keep you posted if any additional information is required. thank you.

@pgentile

Copy link
Copy Markdown
Author

Hi @hemasekhar-p,

Do you know when this PR will be reviewed?

The configuration of this parameter is already available in the Python and Kotlin SDKs.
Having this knob is very useful to get better accuracy of results when I use the RAG Engine.

Thanks

Comment thread core/src/main/java/com/google/adk/tools/retrieval/VertexAiRagRetrieval.java Outdated
Comment thread core/src/main/java/com/google/adk/tools/retrieval/VertexAiRagRetrieval.java Outdated
Comment thread core/src/test/java/com/google/adk/tools/retrieval/VertexAiRagRetrievalTest.java Outdated
@damianmomotgoogle damianmomotgoogle added waiting on reporter Waiting for reaction by reporter. Failing that, maintainers will eventually closed it as stale. and removed needs review labels Oct 16, 2026
@pgentile2

Copy link
Copy Markdown

Hi @damianmomotgoogle,

I've addressed your review feedback and pushed the fixes.

Thanks 🙏

@damianmomotgoogle damianmomotgoogle 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.

Thx! Can you squash all commits into a single one with conventional commits message ?

@pgentile
pgentile force-pushed the rag_retrieval_similarity_top_k branch from 01a2182 to fa0331c Compare October 19, 2026 13:49
@pgentile

pgentile commented Oct 19, 2026 •

Copy link
Copy Markdown
Author

The commits are now squashed.
I've rebased the PR too.

New builder for the VertexAiRagRetrieval class to configure the similarity top-K parameter
@pgentile
pgentile force-pushed the rag_retrieval_similarity_top_k branch from fa0331c to 71bd1cd Compare October 19, 2026 13:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

waiting on reporter Waiting for reaction by reporter. Failing that, maintainers will eventually closed it as stale.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants