Skip to content

Commit 89daffd

Browse files
authored
Add vertex search tool with integration tests (#73)
* Add vertex search tool with integration tests * Clear notebook cells * Address Marcelo review comments
1 parent 48fb234 commit 89daffd

11 files changed

Lines changed: 1508 additions & 140 deletions

File tree

.env.example

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,11 @@ REPORT_GENERATION_DB__DRIVER="sqlite"
2424
REPORT_GENERATION_DB__DATABASE="implementations/report_generation/data/OnlineRetail.db"
2525
REPORT_GENERATION_DB__QUERY__MODE="ro"
2626

27+
# Vertex AI Search (custom knowledge base) - no API key needed, uses ADC
28+
# On Coder/GCE workspaces the attached service account handles auth automatically.
29+
# Required IAM roles on the service account: roles/discoveryengine.viewer, roles/aiplatform.user
30+
GOOGLE_CLOUD_LOCATION="us-central1"
31+
VERTEX_AI_DATASTORE_ID="projects/{project}/locations/global/collections/default_collection/dataStores/{datastore-id}"
32+
2733
# Report Generation (all optional, defaults are in implementations/report_generation/env_vars.py)
2834
REPORT_GENERATION_OUTPUT_PATH="..."

aieng-eval-agents/aieng/agent_evals/configs.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,21 @@ class Configs(BaseSettings):
160160
web_search_base_url: str | None = Field(default=None, description="Base URL for web search service.")
161161
web_search_api_key: SecretStr | None = Field(default=None, description="API key for web search service.")
162162

163+
# === Vertex AI Search (custom knowledge base) ===
164+
google_cloud_location: str = Field(
165+
default="us-central1",
166+
description="GCP region for Vertex AI model calls. Must match a region that supports Gemini.",
167+
)
168+
vertex_datastore_id: str | None = Field(
169+
default=None,
170+
validation_alias="VERTEX_AI_DATASTORE_ID",
171+
description=(
172+
"Full Vertex AI Search data store resource name. "
173+
"Format: projects/{project}/locations/global/collections/default_collection/dataStores/{id}. "
174+
"Authentication uses Application Default Credentials (ADC) — no API key required."
175+
),
176+
)
177+
163178
# === Report Generation ===
164179
# Defaults are set in the implementations/report_generation/env_vars.py file
165180
report_generation_output_path: str | None = Field(

aieng-eval-agents/aieng/agent_evals/knowledge_qa/__init__.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,13 @@
2121
format_response_with_citations,
2222
)
2323

24-
from .agent import KnowledgeAgentManager, KnowledgeGroundedAgent
24+
from .agent import KnowledgeGroundedAgent
2525
from .data import DeepSearchQADataset, DSQAExample
2626

2727

2828
__all__ = [
2929
# Agent
3030
"KnowledgeGroundedAgent",
31-
"KnowledgeAgentManager",
3231
# Grounding tool
3332
"create_google_search_tool",
3433
"format_response_with_citations",

aieng-eval-agents/aieng/agent_evals/knowledge_qa/agent.py

Lines changed: 0 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -747,80 +747,3 @@ def answer(
747747
"""
748748
logger.info(f"Answering question (sync): {question[:100]}...")
749749
return asyncio.run(self.answer_async(question, session_id))
750-
751-
752-
class KnowledgeAgentManager:
753-
"""Manages KnowledgeGroundedAgent lifecycle with lazy initialization.
754-
755-
This class provides convenient lifecycle management for the knowledge agent,
756-
with lazy initialization and state tracking.
757-
758-
Parameters
759-
----------
760-
config : Configs, optional
761-
Configuration object for client setup. If not provided, creates default.
762-
763-
Examples
764-
--------
765-
>>> manager = KnowledgeAgentManager()
766-
>>> agent = manager.agent
767-
>>> response = await agent.answer_async("What is quantum computing?")
768-
>>> print(response.text)
769-
>>> manager.close()
770-
"""
771-
772-
def __init__(
773-
self,
774-
config: Configs | None = None,
775-
enable_caching: bool = True,
776-
enable_planning: bool = True,
777-
enable_compaction: bool = True,
778-
) -> None:
779-
"""Initialize the client manager.
780-
781-
Parameters
782-
----------
783-
config : Configs, optional
784-
Configuration object. If not provided, creates default config.
785-
enable_caching : bool, default True
786-
Whether to enable context caching.
787-
enable_planning : bool, default True
788-
Whether to enable built-in planning (Gemini thinking mode).
789-
enable_compaction : bool, default True
790-
Whether to enable context compaction.
791-
"""
792-
self._config = config
793-
self._enable_caching = enable_caching
794-
self._enable_planning = enable_planning
795-
self._enable_compaction = enable_compaction
796-
self._agent: KnowledgeGroundedAgent | None = None
797-
self._initialized = False
798-
799-
@property
800-
def config(self) -> Configs:
801-
"""Get or create the config instance."""
802-
if self._config is None:
803-
self._config = Configs() # type: ignore[call-arg]
804-
return self._config
805-
806-
@property
807-
def agent(self) -> KnowledgeGroundedAgent:
808-
"""Get or create the knowledge-grounded agent."""
809-
if self._agent is None:
810-
self._agent = KnowledgeGroundedAgent(
811-
config=self.config,
812-
enable_caching=self._enable_caching,
813-
enable_planning=self._enable_planning,
814-
enable_compaction=self._enable_compaction,
815-
)
816-
self._initialized = True
817-
return self._agent
818-
819-
def close(self) -> None:
820-
"""Close all initialized clients and reset state."""
821-
self._agent = None
822-
self._initialized = False
823-
824-
def is_initialized(self) -> bool:
825-
"""Check if any clients have been initialized."""
826-
return self._initialized

aieng-eval-agents/aieng/agent_evals/tools/__init__.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
33
This package provides modular tools for:
44
- Google Search (search.py)
5+
- Vertex AI Search / custom knowledge base (vertex_search.py)
56
- Web content fetching - HTML and PDF (web.py)
67
- File downloading and searching - CSV, XLSX, text (file.py)
78
- SQL Database access (sql_database.py)
@@ -24,20 +25,23 @@
2425
google_search,
2526
)
2627
from .sql_database import ReadOnlySqlDatabase, ReadOnlySqlPolicy
28+
from .vertex_search import create_vertex_search_tool, vertex_search
2729
from .web import (
2830
create_web_fetch_tool,
2931
web_fetch,
3032
)
3133

3234

3335
__all__ = [
34-
# Search tools
36+
# Google Search tools
3537
"create_google_search_tool",
3638
"google_search",
3739
"format_response_with_citations",
38-
"google_search",
3940
"GroundedResponse",
4041
"GroundingChunk",
42+
# Vertex AI Search tools (custom knowledge base)
43+
"create_vertex_search_tool",
44+
"vertex_search",
4145
# Web tools (HTML pages and PDFs)
4246
"web_fetch",
4347
"create_web_fetch_tool",

0 commit comments

Comments
 (0)