Skip to content

feat(expansion): OpenAI-compat JSON mode replaces Anthropic tool use#165

Closed
MichaelChristopher wants to merge 1 commit into
garrytan:masterfrom
MichaelChristopher:pr/openai-compat-expansion
Closed

feat(expansion): OpenAI-compat JSON mode replaces Anthropic tool use#165
MichaelChristopher wants to merge 1 commit into
garrytan:masterfrom
MichaelChristopher:pr/openai-compat-expansion

Conversation

@MichaelChristopher

Copy link
Copy Markdown

Summary

Replaces the Anthropic SDK dependency in query expansion with the OpenAI-compatible SDK, enabling multi-provider routing through any OpenAI-compatible endpoint (OpenRouter, Ollama, llama.cpp, etc.).

Key Changes

  • Swaps Anthropic SDK for openai package in expansion pipeline
  • Uses JSON mode (response_format: { type: "json_object" }) instead of Anthropic tool use syntax
  • Configurable via env vars: GBRAIN_EXPANSION_MODEL, GBRAIN_EXPANSION_BASE_URL, and standard provider credential conventions
  • Adds CJK support: character-based counting for East Asian text
  • Graceful fallback to [query] on malformed responses

Motivation

The hard dependency on the Anthropic SDK for query expansion limits gbrain to a single provider. This change enables:

  • Running expansion locally (Ollama, llama.cpp)
  • Using any OpenAI-compatible cloud provider
  • Removing the Anthropic SDK as a required dependency
  • Cost reduction for high-volume search workloads

Changes

  • src/core/search/expansion.ts: 62 insertions, 41 deletions

Swap @anthropic-ai/sdk for openai package so multi-query expansion can
route through any OpenAI-compat provider. Default model changed from
claude-haiku-4-5-20251001 to gemma4:latest (local Ollama) for long-term
stability: no credential dependency, zero cost, offline-capable.

JSON mode (response_format: json_object) is used instead of Anthropic
tool use syntax for portability across providers. Existing try/catch
fallback to [query] handles malformed responses gracefully.

Env vars:
- GBRAIN_EXPANSION_MODEL (default: gemma4:latest)
- GBRAIN_EXPANSION_BASE_URL (falls back to OPENAI_BASE_URL)

Local patch 0004/0004 for Phase B gbrain adoption.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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