Skip to content

Conversation

saeedseyfi
Copy link

@saeedseyfi saeedseyfi commented Oct 11, 2025

Summary

Add optional dimensions constructor argument to VertexAIEmbeddings class. This allows users to set a default output dimensionality that will be used for all embedding requests unless explicitly overridden.

Changes

  • Add dimensions field to VertexAIEmbeddings with default value None
  • Update embed() method to use constructor default when dimensions not specified in method call
  • Explicit dimensions in method calls override the constructor default
  • Full backward compatibility maintained - existing code continues to work unchanged

Usage Example

# Set default dimensions in constructor
embeddings = VertexAIEmbeddings(model="text-embedding-004", dimensions=128)

# Uses 128 dimensions (from constructor)
embeddings.embed(["hello", "world"])

# Overrides with 256 dimensions
embeddings.embed(["hello", "world"], dimensions=256)

# Backward compatible - no dimensions specified
embeddings = VertexAIEmbeddings(model="text-embedding-004")
embeddings.embed(["hello", "world"])  # Uses model's default

Test Plan

  • Added 5 new unit tests covering all scenarios
  • Test that constructor dimensions are used when not specified in embed()
  • Test that explicit dimensions override constructor default
  • Test backward compatibility when no default dimensions specified
  • Test default dimensions work with embed_documents() and embed_query()
  • All 10 unit tests pass
  • Code quality checks pass (lint, format, mypy)

@saeedseyfi saeedseyfi changed the title feat(vertexai): add default dimensions parameter to VertexAIEmbeddings feat(vertex): add default dimensions parameter to VertexAIEmbeddings Oct 11, 2025
Add optional 'dimensions' constructor argument to VertexAIEmbeddings class.
This allows users to set a default output dimensionality that will be used
for all embedding requests unless explicitly overridden.

- Add 'dimensions' field with default value None
- Update embed() method to use constructor default when dimensions not specified
- Maintain backward compatibility - existing code continues to work unchanged
- Add comprehensive unit tests for default dimensions behavior
@saeedseyfi saeedseyfi force-pushed the feat/vertexai-default-dimensions branch from a2f6b23 to 232866b Compare October 11, 2025 18:27
@saeedseyfi
Copy link
Author

saeedseyfi commented Oct 15, 2025

Hey @lkuligin, thanks for your approval, would you merge as well?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants