Skip to content

feat(google): add support for google embeddings and reranker#863

Open
ParadiseN1 wants to merge 2 commits intovectorize-io:mainfrom
ParadiseN1:feat/add-google-embeddings-and-rerank
Open

feat(google): add support for google embeddings and reranker#863
ParadiseN1 wants to merge 2 commits intovectorize-io:mainfrom
ParadiseN1:feat/add-google-embeddings-and-rerank

Conversation

@ParadiseN1
Copy link
Copy Markdown
Contributor

@ParadiseN1 ParadiseN1 commented Apr 3, 2026

Summary

Adds full Google Cloud infrastructure support for Hindsight by adding google's embeddings and reranking models.
With this changes it is now possible to run Hindsight fully on Google Cloud's infrastructure (which is important for my production usecase):

  • Google embeddings: GeminiEmbeddings provider using google.genai SDK with both Gemini API (key auth) and Vertex AI (service account/ADC) support. Includes L2 normalization for truncated dimensions — Gemini only returns normalized vectors at full 3072 dims.
  • Google reranker: GoogleCrossEncoder provider using the Discovery Engine REST Ranking API with httpx + google-auth.

Changes

  • New embeddings provider: hindsight-api-slim/hindsight_api/engine/embeddings.pyGeminiEmbeddings with Gemini API key and Vertex AI auth, configurable output_dimensionality, L2 normalization via numpy
  • New reranker provider: hindsight-api-slim/hindsight_api/engine/cross_encoder.pyGoogleCrossEncoder using REST API with OAuth2 bearer tokens
  • Config: Added env vars for both providers (EMBEDDINGS_GEMINI_*, EMBEDDINGS_VERTEXAI_*, RERANKER_GOOGLE_*) with fallback to LLM Vertex AI keys
  • Factory: Added google case to both create_embeddings_from_env() and create_cross_encoder_from_env()
  • Docs: Updated configuration.md with Google embeddings and reranker config

Usage

# Google embeddings (Gemini API key)
export HINDSIGHT_API_EMBEDDINGS_PROVIDER=google
export HINDSIGHT_API_EMBEDDINGS_GEMINI_API_KEY=your-key
export HINDSIGHT_API_EMBEDDINGS_GEMINI_OUTPUT_DIMENSIONALITY=768

# Google embeddings (Vertex AI — auto-detected when project ID is set)
export HINDSIGHT_API_EMBEDDINGS_PROVIDER=google
export HINDSIGHT_API_EMBEDDINGS_VERTEXAI_PROJECT_ID=your-gcp-project-id
export HINDSIGHT_API_EMBEDDINGS_VERTEXAI_SERVICE_ACCOUNT_KEY=/path/to/key.json

# Google reranker (Discovery Engine)
export HINDSIGHT_API_RERANKER_PROVIDER=google
export HINDSIGHT_API_RERANKER_GOOGLE_PROJECT_ID=your-gcp-project-id
export HINDSIGHT_API_RERANKER_GOOGLE_SERVICE_ACCOUNT_KEY=/path/to/key.json  # optional, uses ADC if unset

Tested

  • Embeddings: Gemini API and Vertex AI auth, dimension detection, output_dimensionality (768, 256), L2 norm verified = 1.0
  • Reranker: semantic ranking validation across 3 query scenarios with manual score inspection
  • End-to-end: full Google stack (gemini-3.1-flash-lite-preview LLM + gemini-embedding-001 + semantic-ranker-default-004) — retain 5 memories, recall 5 queries, reflect 2 queries
  • 25 unit tests for GeminiEmbeddings (init, encode, batching, dimensionality, factory)
  • 17 unit tests for GoogleCrossEncoder (init, predict, batching, auth, factory)
  • Lints pass
  • Documentation updated

@ParadiseN1 ParadiseN1 changed the title Add support for google embeddings gemini/vertex and google reranker v… feat: Add support for google embeddings gemini/vertex and google reranker v… Apr 3, 2026
@ParadiseN1 ParadiseN1 changed the title feat: Add support for google embeddings gemini/vertex and google reranker v… feat(google): add support for google embeddings gemini/vertex and google reranker v… Apr 3, 2026
@ParadiseN1 ParadiseN1 changed the title feat(google): add support for google embeddings gemini/vertex and google reranker v… feat(google): add support for google embeddings and reranker Apr 3, 2026
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.

1 participant