Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Vertex AI Gemini grounding with Google Search and Vertex data stores #547

Closed
chrisraygill opened this issue Jul 4, 2024 · 3 comments · Fixed by #640
Closed

Support Vertex AI Gemini grounding with Google Search and Vertex data stores #547

chrisraygill opened this issue Jul 4, 2024 · 3 comments · Fixed by #640
Assignees
Labels
feature New feature or request go js

Comments

@chrisraygill
Copy link
Contributor

Is your feature request related to a problem? Please describe.

Vertex AI offers the ability to ground responses for Gemini models using Google Search or your own data in within Vertex AI Search datas stores.

It appears to supported in the Python and Node.js SDK, but not yet in the Go SDK.

In the Vertex AI Gemini API, it works by passing in the grounding mechanism as a tool to the model, like so (Node.js):

async function generateContentWithVertexAISearchGrounding() {
  const generativeModelPreview = vertexAI.preview.getGenerativeModel({
    model: textModel,
    // The following parameters are optional
    // They can also be passed to individual content generation requests
    safetySettings: [{category: HarmCategory.HARM_CATEGORY_DANGEROUS_CONTENT, threshold: HarmBlockThreshold.BLOCK_MEDIUM_AND_ABOVE}],
    generationConfig: {maxOutputTokens: 256},
  });

  const vertexAIRetrievalTool = {
    retrieval: {
      vertexAiSearch: {
        datastore: 'projects/.../locations/.../collections/.../dataStores/...',
      },
      disableAttribution: false,
    },
  };
  const result = await generativeModelPreview.generateContent({
    contents: [{role: 'user', parts: [{text: 'Why is the sky blue?'}]}],
    tools: [vertexAIRetrievalTool],
  })
  const response = result.response;
  const groundingMetadata = response.candidates[0].groundingMetadata;
  console.log("Grounding metadata is: ", JSON.stringify(groundingMetadata));
}
generateContentWithVertexAISearchGrounding();

I'm not sure how this would work with Genkit's current design for specifying tools in a generation request.

@chrisraygill chrisraygill added feature New feature or request js go labels Jul 4, 2024
@chrisraygill chrisraygill moved this to Todo in Genkit Backlog Jul 4, 2024
@pr-Mais pr-Mais self-assigned this Jul 9, 2024
@chrisraygill
Copy link
Contributor Author

@pavelgj from a design perspective, any thoughts on how we might do this?

Maybe just making them custom configuration parameters for the Vertex Gemini models rather than tools? Not sure if that would have odd downstream effects when it comes to tool handling stuff like forced function calling.

@chrisraygill
Copy link
Contributor Author

@pr-Mais any proposals from you on how this might look?

@pr-Mais
Copy link
Member

pr-Mais commented Jul 15, 2024

@chrisraygill I was thinking, we could turn it into a generic tool, as a start it will only support vertex ai models through this API, later we add a custom implementation for it to be used with other models.

Update: after looking deeper into genkit's tools, this could be tricky. As you mentioned, a better solution is to add it as a custom param in the generate request specific to vertexai plugin. Something like:

const GeminiConfigSchema = GenerationCommonConfigSchema.extend({
  safetySettings: z.array(SafetySettingsSchema).optional(),
  vertexRetriever: z
    .object({
      vertexAiSearch: z
        .object({
          datastore: z.string(),
        })
        .optional(),
      googleSearchRetrieval: z.boolean().optional(),
      disableAttribution: z.boolean().optional(),
    })
    .optional(),
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request go js
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

2 participants