You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# RAG with Generative Models in Google GenAI SDK and Vertex AI SDK
2
+
3
+
This document outlines the file paths and class definitions relevant to integrating `RagRetrievalConfig` and its `metadata_filter` within the `Tool` input for `generate_content` in both the Google GenAI SDK (`google.genai`) and the Vertex AI SDK (`google.cloud.aiplatform`).
4
+
5
+
## Relationship between SDKs
6
+
7
+
While both SDKs target the Vertex AI platform, they have independent implementations for `generate_content`:
8
+
9
+
***Google GenAI SDK (`google.genai`)**: A standalone, Pydantic-based SDK that maps directly to the Gemini REST API. It does **not** depend on the Vertex AI Python SDK's runtime code for generation. It uses its own types and transformation logic (in `models.py`) to call the API.
10
+
***Vertex AI SDK (`google.cloud.aiplatform.vertexai`)**: A high-level SDK that uses GAPIC (proto-based) clients internally. It has its own `GenerativeModel` implementation in `_generative_models.py`.
11
+
12
+
## Relevant File Paths
13
+
14
+
### Google GenAI SDK (`google.genai`)
15
+
16
+
***`google3/third_party/py/google/genai/types.py`**: Defines Pydantic models for `Tool`, `Retrieval`, `VertexRagStore`, `RagRetrievalConfig`, and `RagRetrievalConfigFilter`. **Verified**: These types already include the `metadata_filter` field.
17
+
***`google3/third_party/py/google/genai/models.py`**: Contains the logic to transform GenAI types to Vertex AI REST API format (see `_Tool_to_vertex`). **Note**: Explicit mapping for all `Retrieval` children to camelCase might be needed here if the API is case-sensitive.
18
+
19
+
### Vertex AI SDK (`google.cloud.aiplatform.vertexai`)
20
+
21
+
***`google3/third_party/py/google/cloud/aiplatform/vertexai/generative_models/_generative_models.py`**: Contains the core implementation of `GenerativeModel`. Includes the `grounding` namespace with `Retrieval` and `VertexRagStore` classes.
22
+
***`google3/third_party/py/google/cloud/aiplatform/vertexai/preview/generative_models.py`**: Contains the `_preview_parse_vertex_rag_store_to_api` function which converts SDK types to GAPIC proto messages.
23
+
***`google3/third_party/py/google/cloud/aiplatform/vertexai/preview/rag/utils/resources.py`**: Defines the Python dataclasses for `RagRetrievalConfig`, `Filter`, etc., used by the Vertex AI SDK.
24
+
25
+
## Unit Test File Locations
26
+
27
+
***`google3/third_party/py/google/genai/tests/models/test_generate_content_tools.py`**: Tests for RAG tools in the GenAI SDK.
28
+
***`google3/third_party/py/google/cloud/aiplatform/tests/unit/vertexai/test_generative_models.py`**: Tests for `GenerativeModel` in the Vertex AI SDK.
29
+
30
+
## Current Implementation Status
31
+
32
+
### Vertex AI SDK (google-cloud-aiplatform)
33
+
34
+
1.**`grounding.VertexRagStore`**: **Implemented**. Exists in `_generative_models.py` and correctly holds `RagResource` and `RagRetrievalConfig`.
35
+
2.**`grounding.Retrieval`**: **Implemented**. Accepts `VertexRagStore` as a source and correctly routes to the preview parser.
36
+
3.**Mapping to GAPIC**: **Implemented**. The function `_preview_parse_vertex_rag_store_to_api` in `preview/generative_models.py` correctly maps `metadata_filter` to the underlying proto message.
37
+
38
+
### Google GenAI SDK (google.genai)
39
+
40
+
1.**Type Definitions**: **Implemented**. `types.py` has all required classes for RAG with `metadata_filter`.
41
+
2.**Mapping to REST**: **Partial/Pending**. `models.py` passes the `Retrieval` object. If the backend requires camelCase keys for nested RAG fields, explicit mapping in `_Tool_to_vertex` or a dedicated `_Retrieval_to_vertex` function is required.
42
+
43
+
## Next Steps
44
+
45
+
1.**Verify GenAI SDK REST Mapping**: Ensure that `metadata_filter` and other RAG fields are correctly serialized to camelCase (e.g., `metadataFilter`) when calling the Vertex AI REST API from `google.genai`.
46
+
2.**Add End-to-End Tests**: Add a test case in `google.genai/tests/models/test_generate_content_tools.py` that specifically uses a `metadata_filter` and verifies the resulting request payload.
0 commit comments