Commit Graph

7 Commits

Author SHA1 Message Date
Surapong Kanoktipsatharporn 2869ab3c5f feat: Separate embedding configuration from chat model configuration
This commit implements a comprehensive solution for separating embedding
and chat model configurations, enabling flexible provider combinations
and graceful handling of embedding failures.

## Problem Statement

Previously, the TradingAgents memory system used the same backend_url for
both chat models and embeddings. This caused critical failures when:

- Using OpenRouter for chat (doesn't support OpenAI embedding endpoints)
- Using Anthropic/Google for chat (don't provide embeddings)
- The embedding endpoint returned HTML error pages instead of JSON
- Users wanted to mix providers (e.g., OpenRouter chat + OpenAI embeddings)

Error example:
  AttributeError: 'str' object has no attribute 'data'
  # Caused by: OpenRouter returned HTML page instead of embedding JSON

## Solution

Implemented three key features:

1. **Separate Embedding Client Configuration**
   - New config parameters independent of chat LLM settings
   - embedding_provider: "openai", "ollama", or "none"
   - embedding_backend_url: Separate API endpoint
   - embedding_model: Specific model to use
   - enable_memory: Boolean flag to enable/disable memory

2. **Multiple Provider Support**
   - OpenAI: Production-grade embeddings (recommended)
   - Ollama: Local embeddings for offline/development
   - None: Disable memory system entirely

3. **Graceful Fallback**
   - System continues when embeddings fail
   - Comprehensive error logging
   - Memory operations return empty results instead of crashing
   - Agents function without historical context when memory disabled

## Changes

### Core Framework
- tradingagents/default_config.py: Added 4 new embedding config params
- tradingagents/agents/utils/memory.py: Complete refactor with error handling
- tradingagents/graph/trading_graph.py: Separated embedding initialization

### CLI/User Interface
- cli/utils.py: Added select_embedding_provider() function
- cli/main.py: Added Step 7 for embedding provider selection

### Documentation (New Files)
- docs/EMBEDDING_CONFIGURATION.md: Complete usage guide (381 lines)
- docs/EMBEDDING_MIGRATION.md: Implementation details (374 lines)
- CHANGELOG_EMBEDDING.md: Release notes (225 lines)
- FEATURE_EMBEDDING_README.md: Branch overview (418 lines)

### Testing & Verification
- tests/test_embedding_config.py: Comprehensive test suite
- verify_config.py: Simple config verification script

## Example Usage

```python
# OpenRouter for chat, OpenAI for embeddings
config = {
    "llm_provider": "openrouter",
    "backend_url": "https://openrouter.ai/api/v1",
    "deep_think_llm": "deepseek/deepseek-chat-v3-0324:free",

    "embedding_provider": "openai",
    "embedding_backend_url": "https://api.openai.com/v1",
    "embedding_model": "text-embedding-3-small",
    "enable_memory": True,
}
```

## Backward Compatibility

 100% Backward Compatible - No breaking changes!

Existing configurations work without modification. Smart defaults
applied when embedding settings are omitted.

## Testing

- All core files pass diagnostics with no errors
- Configuration verification script passes all checks
- Supports scenarios: OpenRouter+OpenAI, All Ollama, Disabled Memory
- Graceful fallback tested for invalid URLs and missing API keys

## Benefits

- Enables using OpenRouter/other providers for chat
- Reduces costs (can use local embeddings or disable memory)
- Improves reliability (graceful degradation on failures)
- Maintains full backward compatibility
- Comprehensive documentation and examples

Fixes: OpenRouter compatibility issues
Closes: Embedding/chat provider coupling
Implements: Graceful fallback for memory operations
2025-10-20 15:24:51 +07:00
Max Wong 43aa9c5d09
Local Ollama (#53)
- Fix typo 'Start' 'End'
- Add llama3.1 selection
- Use 'quick_think_llm' model instead of hard-coding GPT
2025-06-26 00:27:01 -04:00
Yijia Xiao 26c5ba5a78
Revert "Docker support and Ollama support (#47)" (#57)
This reverts commit 78ea029a0b.
2025-06-26 00:07:58 -04:00
Geeta Chauhan 78ea029a0b
Docker support and Ollama support (#47)
- Added support for running CLI and Ollama server via Docker
- Introduced tests for local embeddings model and standalone Docker setup
- Enabled conditional Ollama server launch via LLM_PROVIDER
2025-06-25 23:57:05 -04:00
Edward Sun da84ef43aa main works, cli bugs 2025-06-15 22:20:59 -07:00
maxer137 99789f9cd1 Add support for other backends, such as OpenRouter and olama
This aims to offer alternative OpenAI capable api's.
This offers people to experiment with running the application locally
2025-06-11 14:19:25 +02:00
Yijia-Xiao cc97cb6d5d chore(release): v0.1.0 – initial public release of TradingAgents 2025-06-05 04:27:57 -07:00