Configuring Embedding Providers for Semantic Search in CRG: 5 Supported Backends

Code-Review-Graph supports five embedding providers—Local (sentence-transformers), Google Gemini, MiniMax, OpenAI-compatible, and Voyage AI—selected via the get_provider() factory function in embeddings.py using either explicit parameters or environment variables.

The tirth8205/code-review-graph repository enables semantic code search by vectorizing graph nodes through a pluggable embedding pipeline. Configuring embedding providers for semantic search in CRG involves selecting a backend via the EmbeddingProvider interface and setting the required environment variables for cloud-based services.

Available Embedding Providers

The embedding subsystem is defined in code_review_graph/embeddings.py, which declares the abstract EmbeddingProvider interface and five concrete implementations. Valid provider identifiers are stored in the _VALID_PROVIDERS set at line 69.

Local Sentence-Transformers Provider

The LocalEmbeddingProvider class runs embeddings entirely on-premises using the sentence-transformers library. It is the default when no provider is specified. Set CRG_EMBEDDING_MODEL to override the default all-MiniLM-L6-v2 model (defined as LOCAL_DEFAULT_MODEL at line 68).

Google Gemini Provider

The GoogleEmbeddingProvider class interfaces with Google's embedding API. Activation requires provider="google" and the GOOGLE_API_KEY environment variable. The model defaults to "gemini-embedding-001" if not explicitly provided.

MiniMax Provider

The MiniMaxEmbeddingProvider targets the MiniMax embo-01 embedding model. Specify provider="minimax" and export MINIMAX_API_KEY to authenticate requests.

OpenAI-Compatible Provider

The OpenAIEmbeddingProvider supports any OpenAI-compatible endpoint, including custom local servers. It requires three environment variables: CRG_OPENAI_API_KEY, CRG_OPENAI_BASE_URL, and CRG_OPENAI_MODEL. Optional tuning parameters include CRG_OPENAI_DIMENSION and CRG_OPENAI_BATCH_SIZE.

Voyage AI Provider

The VoyageEmbeddingProvider connects to Voyage AI's embedding service. It requires VOYAGE_API_KEY and accepts optional configuration via CRG_VOYAGE_BASE_URL, CRG_VOYAGE_MODEL, CRG_VOYAGE_DIMENSION, CRG_VOYAGE_DTYPE, CRG_VOYAGE_BATCH_SIZE, and rate-limit controls.

Provider Selection Logic

The get_provider() function (lines 72-119) serves as the factory for provider instantiation. It normalizes the provider name to lowercase, validates it against _VALID_PROVIDERS, and implements fallback logic: if no provider is specified but CRG_OPENAI_API_KEY and CRG_OPENAI_BASE_URL exist, it automatically selects the OpenAI provider.

def get_provider(provider: str | None = None, model: str | None = None) -> EmbeddingProvider | None:
    # Normalise the name

    name = provider.strip().lower() if provider else ""
    # Validate

    if name and name not in _VALID_PROVIDERS:
        raise ValueError(...)
    # Implicit OpenAI when env vars are present

    if provider is None and os.environ.get("CRG_OPENAI_API_KEY") and os.environ.get("CRG_OPENAI_BASE_URL"):
        name = "openai"
    # Dispatch to the concrete class …

Cloud Egress Warnings

When a cloud provider is selected and the target URL is not localhost, CRG invokes _warn_cloud_egress (lines 443-466) to print a security warning about sending code snippets to external APIs. Suppress this warning by setting CRG_ACCEPT_CLOUD_EMBEDDINGS=1.

Provider Identity and Vector Re-embedding

Each provider exposes a name property encoding the backend configuration (e.g., openai:text-embedding-3-small@https://api.openai.com). This identifier is persisted in the SQLite embeddings table. The EmbeddingStore.embed_nodes method (lines 100-119) compares this stored name against the current provider; a mismatch triggers automatic re-embedding of affected nodes to ensure vector consistency.

Practical Configuration Examples

Use the default local provider without any environment variables:

from code_review_graph.embeddings import EmbeddingStore, get_provider

store = EmbeddingStore(db_path="my_graph.db")           # provider defaults to "local"

print(store.provider.name)                             # → "local:all-MiniLM-L6-v2"

Switch to OpenAI embeddings via environment variables:

import os
os.environ["CRG_OPENAI_API_KEY"] = "sk-…"
os.environ["CRG_OPENAI_BASE_URL"] = "https://api.openai.com/v1"
os.environ["CRG_OPENAI_MODEL"] = "text-embedding-3-small"

store = EmbeddingStore(db_path="my_graph.db", provider="openai")
print(store.provider.name)   # → "openai:text-embedding-3-small@https://api.openai.com"

Explicitly request the MiniMax provider:

import os
os.environ["MINIMAX_API_KEY"] = "your‑minimax‑key"

store = EmbeddingStore(db_path="my_graph.db", provider="minimax")
print(store.provider.name)   # → "minimax:embo-01"

Perform a semantic search using the configured provider:

results = store.search(query="how to authenticate a request", limit=5)
for qname, score in results:
    print(f"{qname}: {score:.4f}")

Summary

  • CRG abstracts embedding generation behind the EmbeddingProvider interface in code_review_graph/embeddings.py.
  • Five backends are supported: Local, Google Gemini, MiniMax, OpenAI-compatible, and Voyage AI.
  • Select providers via get_provider() using explicit arguments or environment-driven defaults.
  • Cloud providers trigger security warnings unless CRG_ACCEPT_CLOUD_EMBEDDINGS=1 is set.
  • Provider identity tracking ensures automatic re-embedding when backend configurations change.

Frequently Asked Questions

How do I switch from local to OpenAI embeddings in CRG?

Set the three required environment variables (CRG_OPENAI_API_KEY, CRG_OPENAI_BASE_URL, CRG_OPENAI_MODEL) and pass provider="openai" to EmbeddingStore, or rely on the implicit selection when these variables exist and no provider is specified. The get_provider() function automatically detects the OpenAI configuration when both the API key and base URL are present.

What happens if I change the embedding model or provider after creating the graph?

CRG detects the change via the provider name property stored in the database and automatically triggers re-embedding of nodes through the embed_nodes logic (lines 100-119), ensuring search results use consistent vectors and preventing stale embeddings from mixing with new ones.

Is it safe to use cloud embedding providers with proprietary code?

By default, CRG warns when sending data to non-localhost URLs via _warn_cloud_egress (lines 443-466). You must explicitly set CRG_ACCEPT_CLOUD_EMBEDDINGS=1 to acknowledge the risk of code egress before proceeding with cloud-based providers such as Google, MiniMax, OpenAI, or Voyage.

Which provider should I use for offline or air-gapped environments?

Use the LocalEmbeddingProvider (default) with provider="local" or no configuration, which runs sentence-transformers locally and requires no API keys or external network access. Set CRG_EMBEDDING_MODEL to specify a different local model if needed.

Have a question about this repo?

These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:

Share the following with your agent to get started:
curl -s "https://instagit.com/install.md"

Works with
Claude Codex Cursor VS Code OpenClaw Any MCP Client

Maintain an open-source project? Get it listed too →