VertexAISearch (grounding from data store). 400 Request contains an invalid argument.

I am trying to use the Vertex AI search grounding. I followed this notebook.
I keep getting a InvalidArgument: 400 Request contains an invalid argument.

this is my stripped down code:

import vertexai
from vertexai.generative_models import Tool, GenerativeModel
from vertexai.preview.generative_models import grounding as preview_grounding

DATA_STORE_ID = "xxxx_1720852873938"
DATA_STORE_PROJECT_ID = "xxxxx"
DATA_STORE_REGION="global"

vertexai.init(project=DATA_STORE_PROJECT_ID, location='us-central1')

datastore = f"projects/{DATA_STORE_PROJECT_ID}/locations/{DATA_STORE_REGION}/collections/default_collection/dataStores/{DATA_STORE_ID}"
tool = Tool.from_retrieval(
    preview_grounding.Retrieval(preview_grounding.VertexAISearch(datastore=datastore))
)
model = GenerativeModel("gemini-1.5-pro-001")
PROMPT = "what does a F rating mean?"
response = model.generate_content(PROMPT, tools=[tool])
print(response)

The interesting thing is that vertex studio fails with the same error.

I carefully double checked the path of the datastore and all other params.

bug?

I’ll appreciate any help or pointers.

Thank you.

3 Likes

I’m not sure, but try removing or escaping the question mark in your prompt text see if that’s what causing the problem.

2 Likes

it seems that the error message has been updated now and the documentation too:


InvalidArgument: 400 Cannot use enterprise edition features (website search, multi-modal search, extractive answers/segments, etc.) in a standard edition search engine. Please follow [https://cloud.google.com/generative-ai-app-builder/docs/enterprise-edition#toggle-enterprise](https://cloud.google.com/generative-ai-app-builder/docs/enterprise-edition#toggle-enterprise) to enable Enterprise edition.

For anyone with the same issue: You need to create a dummy App in agent builder and associate the data store to it. Then enable Enterprise Edition in the configuration of the app before using it for grounding.

All working now!

2 Likes

I have created a dummy app with enterprise enabled feature and connected it to a data store which is connected to a gcs pdf file with synchronization every 24 hours.

I am using Gemini flash model: gemini-1.5-flash-001

This is my sample code which always is still returning error:: 400 Request contains an invalid argument. Any suggestions

def generate_grounded_content(data_store_path: str, generation_config: PartsType, safety_settings: SafetySettingsType,
                              model: generative_models.GenerativeModel, prompt: str):
    tool = Tool.from_retrieval(
        grounding.Retrieval(grounding.VertexAISearch(datastore=data_store_path))
    )
    logger.info(f"Tool created")
    response = model.generate_content(
        prompt,
        tools=[tool],
        generation_config=GenerationConfig(temperature=0.0, max_output_tokens=8192, top_p=0.95, top_k=40),
        safety_settings=safety_settings
    )
    logger.info(f"Response received")
    response_text = response.text
    logger.info(f"Response text: {response_text}")
    return response_text
2 Likes

have you been able to fix this? I am having the same issue too.

4 Likes

me too, having the same issue:

Failed to submit prompt
Error message: “Request contains an invalid argument.”

Status: 400 Error code: 3

Request ID: 6924843284189509449

3 Likes

Any updates with this issue?
I am stuck on this issue for the last 2 months.

2 Likes

Hi:

I am having the same issue. I created a structured data store with the attached schema.

I also created a generic search app with enterprise enabled and connected it to the above schema.

I am using the following code to use the data store in my vertex ai search and get the “InvalidArgument: 400 Request contains an invalid argument.” error. Any help would be appreciated.

mport vertexai
from IPython.display import Markdown, display
from vertexai.preview.generative_models import (
    GenerationConfig,
    GenerativeModel,
    Tool,
    grounding,
)

DATA_STORE_ID = "care-plan-templates_1726575266786"
DATA_STORE_PROJECT_ID = 'xxxxx'
DATA_STORE_REGION = 'global'

# TODO (developer): update project_id
vertexai.init(project=DATA_STORE_PROJECT_ID, location="us-central1")

model = GenerativeModel("gemini-1.0-pro")

data_store = f"projects/{DATA_STORE_PROJECT_ID}/locations/{DATA_STORE_REGION}/collections/default_collection/dataStores/{DATA_STORE_ID}"
tool = Tool.from_retrieval(
    grounding.Retrieval(
        grounding.VertexAISearch(datastore=data_store)
    )
)

prompt = "what is the care plan for the chronic condition asthma?"

# try:
response = model.generate_content(prompt, 
                                  tools=[tool],
                                  generation_config=GenerationConfig(
                                      temperature=0.0,
                                      ),
                                  )
display(Markdown(response.text))
2 Likes

I am much less lettered in coding than everyone here, but I would love to understand at least where the problem is: in the bucket? in the dummy app? in the chat request?

It would be a good first step.

Status 400 error code: 3