Migrate from deprecated text-embedding-004 to gemini-embedding-001
Summary
Google deprecated text-embedding-004 model. The API now returns:
models/text-embedding-004 is not found for API version v1beta, or is not supported for embedContent.
Need to migrate to gemini-embedding-001 (3072 dims) across the codebase.
Breaking Change
Dimension change: 768 → 3072
Existing Elasticsearch indices with 768-dim dense_vectors are incompatible with 3072-dim vectors. All indices must be deleted and re-created.
Affected Files
Code Changes Required
| File | Lines | Change |
|------|-------|--------|
| src/core/rag/gemini.rs | 10, 70, 75, 125-126 | URL, model name, dims 768→3072 |
| src/mcp/rag_handler.rs | 295, 300, 307, 329-330 | URL, model name, dims 768→3072 |
| src/core/elasticsearch/citation_index.rs | 17, 32 | EMBEDDING_DIMS 768→3072 |
| src/cli/commands/rag.rs | 408 | Hardcoded dims 768→3072 |
Already Using New Model (no changes needed)
src/cli/commands/dedupe_content.rs- already usesgemini-embedding-001with 3072 dims
Elasticsearch Indices Affected
| Index Pattern | Created By | Current Dims |
|--------------|------------|--------------|
| ulysses_chunks | rag.rs:424 | 768 |
| citation_embeddings_{run_id} | citation_index.rs:81 | 768 |
Migration Steps
1. Delete Existing Indices
# Delete ulysses_chunks index
curl -X DELETE "localhost:9200/ulysses_chunks"
# Delete all citation embedding indices
curl -X DELETE "localhost:9200/citation_embeddings_*"
2. Update Code
src/core/rag/gemini.rs:
// Line 10: Update URL
const GEMINI_BATCH_EMBED_URL: &str =
"https://generativelanguage.googleapis.com/v1beta/models/gemini-embedding-001:batchEmbedContents";
// Line 70: Update model name
model: "models/gemini-embedding-001".to_string(),
// Line 75: Update dimensions
output_dimensionality: Some(3072),
// Lines 125-126: Update dimension check
if dim != 3072 {
warn!("Expected 3072 dimensions but got {}", dim);
}
src/mcp/rag_handler.rs:
// Lines 295, 300: Update URL and model
"https://generativelanguage.googleapis.com/v1beta/models/gemini-embedding-001:batchEmbedContents?key={}"
"model": "models/gemini-embedding-001",
// Line 307: Update dimensions
"outputDimensionality": 3072
// Lines 329-330: Update dimension check
if embedding.len() != 3072 {
anyhow::bail!("Expected 3072 dimensions, got {}", embedding.len());
}
src/core/elasticsearch/citation_index.rs:
// Line 17: Update constant
const EMBEDDING_DIMS: i32 = 3072;
// Line 32: Update comment
/// 3072-dim embedding vector
src/cli/commands/rag.rs:
// Line 408: Update hardcoded dims
"dims": 3072,
3. Re-create Indices
Run the commands that create indices - they will use the new 3072-dim mapping:
# For ulysses_chunks (via rag command)
cargo run -- rag --index
# For citation indices (created per-run during processing)
# These are created automatically when running the pipeline
4. Re-embed Documents
All documents need to be re-embedded with the new model:
- RAG chunks: Re-run
cargo run -- rag --index - Citations: Re-run affected pipeline stages
Verification
After migration, verify indices have correct dimensions:
curl -s "localhost:9200/ulysses_chunks/_mapping" | jq '.ulysses_chunks.mappings.properties.embedding.dims'
# Should return: 3072
curl -s "localhost:9200/citation_embeddings_*/_mapping" | jq '.[].mappings.properties.embedding.dims'
# Should return: 3072
Rollback
Not applicable - text-embedding-004 is deprecated and no longer available.
This issue has 2 comments on GitHub. Read the full discussion on GitHub ↗