feat: Gemini embedding support via GEMINI_API_KEY env var (zero-config, free tier)#89
feat: Gemini embedding support via GEMINI_API_KEY env var (zero-config, free tier)#89flychicken067 wants to merge 2 commits intogarrytan:masterfrom
Conversation
- embedding.ts: auto-detect GEMINI_API_KEY or OPENAI_API_KEY - hybrid.ts: fix key check to include GEMINI_API_KEY - gemini-embedding-001 at 1536 dims, no schema changes needed - Free tier: 1500 req/day, sufficient for personal knowledge bases Tested on 48-page knowledge base. Cross-language search works: English query finds Chinese notes via semantic similarity.
Required peer dependency for GEMINI_API_KEY auto-detection path. Free tier: 1500 req/day via aistudio.google.com Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
|
+1, applied this locally on v0.12.0 and confirmed it works cleanly. Setup on Alfred (Mac Mini dev box): gh pr checkout 89 -R garrytan/gbrain
bun install
GEMINI_API_KEY=AIza... bun ./src/core/embedding.ts
# → dim: 1536 ✓Why this matters for us:
Minor observation (not blocking): the Would love to see this land — there are 8+ open PRs in this area (#58, #59, #99, #134, #147, #150, #172, #178) which suggests real demand for multi-provider embeddings. The zero-config env-var approach in this PR is the cleanest UX of the bunch. Happy to help with any reviewer asks. |
What this does
Adds Gemini embedding support as a zero-config free alternative to OpenAI.
Set
GEMINI_API_KEYand GBrain uses Gemini automatically — no config file changes, nogbrain initflags.Why env-var auto-detection instead of config flags
The simplest path to a working brain for users without an OpenAI key:
No
--providerflags. No config file edits. Existing OpenAI users are unaffected.Changes (2 files only)
src/core/embedding.ts— multi-provider with auto-detection:GEMINI_API_KEY→OPENAI_API_KEY→ clear error with link to get a keygemini-embedding-001returns 3072 dims by default; sliced to 1536 — no schema changessrc/core/search/hybrid.ts— fix key detection:if (!process.env.OPENAI_API_KEY)(skipped vector search with Gemini key)if (!process.env.OPENAI_API_KEY && !process.env.GEMINI_API_KEY)Real-world test
Tested on a 48-page Chinese/English knowledge base:
gbrain doctorpasses, 100% embedding coverageEnglish question surfaces Chinese article. This is the core value of semantic over keyword search.
Relation to #58
PR #58 takes a config-based approach (
--provider,outputDimensionalityparam).This PR takes an env-var approach (detect key, auto-select provider).
Both maintain 1536-dim compatibility. Different UX tradeoffs — happy to consolidate if preferred.
Verification
Get a free Gemini key: https://aistudio.google.com/apikey
🤖 Generated with Claude Code