Repository navigation
feat(vertexairagtool): expose RAG retrieval configuration - #2324
dhakad22klx wants to merge 10 commits into
Conversation
27e0d7b to
5338a49
Compare
…tps://github.com/dhakad22klx/adk-go into feat/vertexairagtool-expose-rag-retrieval-config
wojtas000
left a comment
There was a problem hiding this comment.
This needs one fix before merge: users can now set top-k and the vector distance threshold in two places each, and nothing says which value the backend uses. The PR's own expected request sends both with different values (top-k 3 and 5, threshold 0.5 and 0.4).
Before this PR, SimilarityTopK and VectorDistanceThreshold were the only way to cap or filter results. Now RAGRetrievalConfig.TopK and RAGRetrievalConfig.Filter.VectorDistanceThreshold set the same things. New accepts both members of each pair and sends both, and every one of these fields is still documented as the knob that controls results. Please choose one rule, test it, and document it on all three fields. Either New returns an error when both members of a pair are set, or you mark SimilarityTopK and VectorDistanceThreshold as superseded and say that RAGRetrievalConfig wins. Then change wantStore() so the copy tests stop treating a conflicting config as the normal case.
On adk-python parity: VertexAiRagRetrieval.__init__ in adk-python (src/google/adk/tools/retrieval/vertex_ai_rag_retrieval.py) takes only rag_corpora, rag_resources, similarity_top_k and vector_distance_threshold, so this option exists only in Go. The package is experimental and the field passes a genai type straight through, so I don't see that as a reason to reject the PR. The empty description should still say why the option belongs here and not in geminitool.New, which can already send any VertexRAGStore, and link a matching adk-python issue if there is one.
The deep copy is complete for every field the tests use, and the copy tests would catch a missing clone. A nil RAGRetrievalConfig leaves requests exactly as they were.
Three adk-python tests in tools/retrieval/test_vertex_ai_rag_retrieval.py fail on main and still fail with this PR: test_vertex_rag_retrieval_for_gemini_2_x, test_vertex_rag_retrieval_for_non_gemini and test_vertex_rag_retrieval_for_non_gemini_with_another_function_tool. They check the store shape adk-python sends to Gemini and its function-declaration fallback for non-Gemini models, which this package doesn't offer. They don't involve retrieval config, so this PR doesn't need to change anything for them. workflow/test_llm_agent_as_node.py::test_parallel_single_turn_nodes_only_see_own_node_input is flaky on main too and doesn't touch this package.
| // RAGRetrievalConfig configures filtering, hybrid search, ranking and context | ||
| // count. Nil leaves the backend defaults in place. These options extend the | ||
| // configuration supported by the Python retrieval tool. | ||
| RAGRetrievalConfig *genai.RAGRetrievalConfig |
There was a problem hiding this comment.
Important: this field overlaps SimilarityTopK (via TopK) and VectorDistanceThreshold (via Filter.VectorDistanceThreshold). New sends both, and no doc says which value applies. Please either reject a config that sets both members of a pair, or document that this field takes precedence and mark the old two as superseded, and add a test for whichever rule you pick.
There was a problem hiding this comment.
Pushed required fixes in latest commit 72a56a0.
|
|
||
| // RAGRetrievalConfig configures filtering, hybrid search, ranking and context | ||
| // count. Nil leaves the backend defaults in place. These options extend the | ||
| // configuration supported by the Python retrieval tool. |
There was a problem hiding this comment.
Nit: please drop the sentence about the Python retrieval tool. It goes stale when adk-python changes. Say instead what the field sends and how it relates to SimilarityTopK and VectorDistanceThreshold.
There was a problem hiding this comment.
Pushed fixes in latest commit.
| } | ||
| } | ||
|
|
||
| func retrievalConfig() *genai.RAGRetrievalConfig { |
There was a problem hiding this comment.
Nit: this fixture sets both vector thresholds and both rankers. The Vertex API accepts only one of each pair, so it describes a request the backend would reject. Use one threshold and one ranker here, and cover the other member of each pair in its own case. Also stop setting conflicting SimilarityTopK/VectorDistanceThreshold values in wantStore().
There was a problem hiding this comment.
pushed fixes in latest commit.
| HybridSearch: &genai.RAGRetrievalConfigHybridSearch{ | ||
| Alpha: new(float32(0.1)), | ||
| }, | ||
| // Filter configures metadata/vector thresholds; Ranking configures reranking. |
There was a problem hiding this comment.
Nit: this comment describes fields the example doesn't set. Remove it or show a real Filter/Ranking line. Also note that the example now turns on hybrid search for any corpus the user points it at.
There was a problem hiding this comment.
Dropped this extra comment in latest commit 0daf029 .
Closes: #2289
Problem:
vertexairagtool.Configdoes not exposeRAGRetrievalConfig, preventing callers from configuring hybrid search, ranking/reranking, filters, and context count.Solution:
Add optional
RAGRetrievalConfig *genai.RAGRetrievalConfig, pass it through toVertexRAGStore, and deep-copy all nested pointers during construction and request processing to preserve mutation isolation.Behavior change
Callers can configure the additional retrieval options. Existing callers that omit the field retain their current behavior.
Testing Plan
Unit Tests:
go test -race -mod=readonly -count=1 -shuffle=on ./....With your source change reverted and your tests kept, which test fails?
Removing pass-through makes
TestProcessRequest_RAGRetrievalConfigfail. Removing nested copies makesTestNew_CopiesConfigandTestProcessRequest_CopiesStorePerRequestfail.Manual End-to-End (E2E) Tests:
Tested against a live Vertex AI RAG corpus containing my resume (pdf file).
Setup, replacing placeholders with the project and corpus used for testing:
Repeated the following prompt with each retrieval configuration:
These runs verify live request acceptance and corpus-grounded responses.
Checklist