feat(providers): add Mistral embedding provider, route registry through dynaconf
Adds a hosted Mistral embedding option (mistral-embed, 1024-dim) alongside the existing Bedrock / OpenAI / Ollama / Simple providers. Implementation mirrors OpenAIProvider: lazy dimension detection with a known-models lookup, chunked batch requests, defensive index sort, and a 429-aware retry decorator. In the same change, ProviderRegistry switches from os.getenv to the dynaconf-backed Settings dataclass so all five providers share a single configuration path. config.py gains the previously-uncovered Bedrock keys, the new Mistral keys, the missing OPENAI_GENERATION_MODEL / OLLAMA_GENERATION_MODEL, and SIMPLE_EMBEDDING_DIMENSION. Auto-detection priority: Bedrock → OpenAI → Mistral → Ollama → Simple. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.7
parent
61cadf7935
commit
3268a13d11
@@ -118,10 +118,16 @@ class ProviderRegistry:
|
||||
@staticmethod
|
||||
def create_provider() -> Provider:
|
||||
# 1. Bedrock (AWS_REGION or BEDROCK_*_MODEL)
|
||||
# 2. Ollama (OLLAMA_BASE_URL)
|
||||
# 3. Simple (fallback)
|
||||
# 2. OpenAI (OPENAI_API_KEY)
|
||||
# 3. Mistral (MISTRAL_API_KEY)
|
||||
# 4. Ollama (OLLAMA_BASE_URL)
|
||||
# 5. Simple (fallback)
|
||||
```
|
||||
|
||||
Configuration is sourced via the dynaconf-backed `Settings` dataclass in
|
||||
`config.py`; the registry reads `get_settings()` rather than `os.getenv`
|
||||
directly, so settings files and env vars share one resolution path.
|
||||
|
||||
**Environment Variables:**
|
||||
|
||||
**Bedrock:**
|
||||
@@ -131,6 +137,17 @@ class ProviderRegistry:
|
||||
- `BEDROCK_EMBEDDING_MODEL`: Model ID for embeddings (e.g., "amazon.titan-embed-text-v2:0")
|
||||
- `BEDROCK_GENERATION_MODEL`: Model ID for text generation (e.g., "anthropic.claude-3-sonnet-20240229-v1:0")
|
||||
|
||||
**OpenAI:**
|
||||
- `OPENAI_API_KEY`: OpenAI API key (or `GITHUB_TOKEN` for GitHub Models)
|
||||
- `OPENAI_BASE_URL`: Optional base URL override for OpenAI-compatible APIs
|
||||
- `OPENAI_EMBEDDING_MODEL`: Embedding model (default: "text-embedding-3-small")
|
||||
- `OPENAI_GENERATION_MODEL`: Generation model (e.g., "gpt-4o-mini")
|
||||
|
||||
**Mistral (embeddings only):**
|
||||
- `MISTRAL_API_KEY`: Mistral API key from console.mistral.ai
|
||||
- `MISTRAL_EMBEDDING_MODEL`: Embedding model (default: "mistral-embed", 1024-dim)
|
||||
- `MISTRAL_BASE_URL`: Optional server URL override (proxies, on-prem)
|
||||
|
||||
**Ollama:**
|
||||
- `OLLAMA_BASE_URL`: Ollama API base URL (e.g., "http://localhost:11434")
|
||||
- `OLLAMA_EMBEDDING_MODEL`: Model for embeddings (default: "nomic-embed-text")
|
||||
|
||||
+63
-3
@@ -410,9 +410,16 @@ DOCUMENT_CHUNK_OVERLAP=50 # Overlapping words between chunks (defaul
|
||||
|
||||
### Embedding Service Configuration
|
||||
|
||||
The server uses an embedding service to generate vector representations. Two options are available:
|
||||
The server picks an embedding provider via auto-detection. Priority order
|
||||
(see `nextcloud_mcp_server/providers/registry.py`):
|
||||
|
||||
#### Ollama (Recommended)
|
||||
1. **Bedrock** — if `AWS_REGION` or `BEDROCK_EMBEDDING_MODEL` is set
|
||||
2. **OpenAI** — if `OPENAI_API_KEY` is set
|
||||
3. **Mistral** — if `MISTRAL_API_KEY` is set
|
||||
4. **Ollama** — if `OLLAMA_BASE_URL` is set
|
||||
5. **Simple** — fallback when nothing else is configured
|
||||
|
||||
#### Ollama (Recommended for self-hosted)
|
||||
|
||||
Use a local Ollama instance for embeddings:
|
||||
|
||||
@@ -422,9 +429,52 @@ OLLAMA_EMBEDDING_MODEL=nomic-embed-text # Default model
|
||||
OLLAMA_VERIFY_SSL=true # Verify SSL certificates
|
||||
```
|
||||
|
||||
#### OpenAI
|
||||
|
||||
Hosted OpenAI embeddings (or any OpenAI-compatible API via `OPENAI_BASE_URL`):
|
||||
|
||||
```dotenv
|
||||
OPENAI_API_KEY=sk-...
|
||||
OPENAI_EMBEDDING_MODEL=text-embedding-3-small # default
|
||||
# OPENAI_BASE_URL=https://models.github.ai/inference # optional
|
||||
```
|
||||
|
||||
#### Mistral
|
||||
|
||||
Hosted Mistral embeddings. Requires a Mistral API key from
|
||||
[console.mistral.ai](https://console.mistral.ai). Currently embeddings only
|
||||
(no text generation).
|
||||
|
||||
```dotenv
|
||||
MISTRAL_API_KEY=...
|
||||
MISTRAL_EMBEDDING_MODEL=mistral-embed # default; produces 1024-dim vectors
|
||||
# MISTRAL_BASE_URL=https://api.mistral.ai # optional override (proxies, on-prem)
|
||||
```
|
||||
|
||||
Switching to or from Mistral forces a new Qdrant collection because the
|
||||
collection name encodes the model (see "Qdrant Collection Naming" above).
|
||||
|
||||
#### Amazon Bedrock
|
||||
|
||||
Bedrock provides hosted embedding models (Titan, Cohere) and uses the AWS
|
||||
credential chain (env vars, profiles, or IAM role):
|
||||
|
||||
```dotenv
|
||||
AWS_REGION=us-east-1
|
||||
BEDROCK_EMBEDDING_MODEL=amazon.titan-embed-text-v2:0
|
||||
# AWS_ACCESS_KEY_ID / AWS_SECRET_ACCESS_KEY are optional — boto3 will use
|
||||
# the standard credential chain if not set.
|
||||
```
|
||||
|
||||
#### Simple Embedding Provider (Fallback)
|
||||
|
||||
If `OLLAMA_BASE_URL` is not set, the server uses a simple random embedding provider for testing. This is **not suitable for production** as it generates random embeddings with no semantic meaning.
|
||||
If no provider env var is set, the server falls back to a simple deterministic
|
||||
embedding provider for testing. This is **not suitable for production** as
|
||||
its embeddings have no semantic meaning.
|
||||
|
||||
```dotenv
|
||||
SIMPLE_EMBEDDING_DIMENSION=384 # optional; default 384
|
||||
```
|
||||
|
||||
### Document Chunking Configuration
|
||||
|
||||
@@ -534,6 +584,16 @@ equivalent.** Operators who need a runtime toggle should open an issue.
|
||||
| `OLLAMA_BASE_URL` | ⚠️ Optional | - | Ollama API endpoint for embeddings |
|
||||
| `OLLAMA_EMBEDDING_MODEL` | ⚠️ Optional | `nomic-embed-text` | Embedding model to use |
|
||||
| `OLLAMA_VERIFY_SSL` | ⚠️ Optional | `true` | Verify SSL certificates |
|
||||
| `OPENAI_API_KEY` | ⚠️ Optional | - | OpenAI API key (selects OpenAI provider) |
|
||||
| `OPENAI_BASE_URL` | ⚠️ Optional | - | OpenAI base URL override (for compatible APIs) |
|
||||
| `OPENAI_EMBEDDING_MODEL` | ⚠️ Optional | `text-embedding-3-small` | OpenAI embedding model |
|
||||
| `MISTRAL_API_KEY` | ⚠️ Optional | - | Mistral API key (selects Mistral provider) |
|
||||
| `MISTRAL_EMBEDDING_MODEL` | ⚠️ Optional | `mistral-embed` | Mistral embedding model (1024-dim) |
|
||||
| `MISTRAL_BASE_URL` | ⚠️ Optional | - | Mistral base URL override (proxies, on-prem) |
|
||||
| `AWS_REGION` | ⚠️ Optional | - | AWS region (selects Bedrock provider) |
|
||||
| `BEDROCK_EMBEDDING_MODEL` | ⚠️ Optional | - | Bedrock embedding model ID |
|
||||
| `BEDROCK_GENERATION_MODEL` | ⚠️ Optional | - | Bedrock generation model ID |
|
||||
| `SIMPLE_EMBEDDING_DIMENSION` | ⚠️ Optional | `384` | Dimension for the fallback Simple provider |
|
||||
| `DOCUMENT_CHUNK_SIZE` | ⚠️ Optional | `512` | Words per chunk for document embedding |
|
||||
| `DOCUMENT_CHUNK_OVERLAP` | ⚠️ Optional | `50` | Overlapping words between chunks (must be < chunk size) |
|
||||
|
||||
|
||||
Reference in New Issue
Block a user