Skip to content

Conversation

@koistya
Copy link

@koistya koistya commented Dec 8, 2025

Background

The Vertex RAG Store API supports filtering retrieval results via rag_file_ids and rag_retrieval_config. This enables dynamic, context-aware RAG queries where users can:

  • Limit searches to specific files (e.g., files associated with a user session)
  • Filter by metadata tags assigned when files were uploaded
  • Set similarity/distance thresholds for quality control

Reference: Google Cloud AI Platform tool.proto

Summary

  • Add ragFileIds parameter for file-level filtering
  • Add metadataFilter parameter for tag-based filtering (recommended for large-scale filtering)
  • Add vectorSimilarityThreshold and vectorDistanceThreshold for quality filtering
  • Fix rag_resources structure to use array format per API spec
await streamText({
  model: vertex("gemini-2.0-flash"),
  tools: {
    rag: vertexRagStore({
      ragCorpus: "projects/my-project/locations/us-central1/ragCorpora/my-corpus",
      // Option 1: Filter by specific file IDs (for small sets)
      ragFileIds: ["file-1", "file-2"],
      // Option 2: Filter by metadata (recommended for large-scale filtering)
      metadataFilter: 'user_id = "user-123" AND project = "acme"',
      // Quality thresholds
      vectorSimilarityThreshold: 0.7,
      topK: 10,
    }),
  },
});

Checklist

  • Tests have been added / updated (for bug fixes / features)
  • Documentation has been added / updated (for bug fixes / features)
  • A patch changeset for relevant packages has been added (for bug fixes / features - run pnpm changeset in the project root)
  • I have reviewed this pull request (self-review)

@koistya koistya force-pushed the dev branch 3 times, most recently from 77fa961 to f2cbec5 Compare December 8, 2025 21:20
@koistya koistya changed the title feat(google): add ragFileIds to vertexRagStore feat(google): add filtering options to vertexRagStore Dec 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant