Expand description
Embedding module for semantic search.
Provides embedding generation using HTTP-based providers:
- Ollama (local) - Recommended for development
- HuggingFace (cloud) - Requires API token
§Architecture
┌──────────────────┐
│ CLI Commands │
│ (status/backfill)│
└────────┬─────────┘
│
▼
┌─────────────────┐
│ Factory │ ← Auto-detects available provider
└────────┬────────┘
│
┌────┴────┐
▼ ▼
┌───────┐ ┌───────────┐
│Ollama │ │HuggingFace│
└───────┘ └───────────┘
│ │
▼ ▼
HTTP HTTP
localhost API§Configuration
Settings are loaded from ~/.savecontext/config.json to maintain
compatibility with the TypeScript MCP server.
Environment variables take precedence:
OLLAMA_ENDPOINT- Ollama server URL (default:http://localhost:11434)OLLAMA_MODEL- Embedding model (default:nomic-embed-text)HF_TOKEN- HuggingFace API tokenHF_MODEL- HuggingFace model (default:sentence-transformers/all-MiniLM-L6-v2)SAVECONTEXT_EMBEDDINGS_ENABLED- Enable/disable embeddings (default:true)
§Usage
ⓘ
use sc::embeddings::{create_embedding_provider, detect_available_providers};
// Detect available providers
let detection = detect_available_providers().await;
println!("Available: {:?}", detection.available);
// Create provider (auto-detects)
if let Some(provider) = create_embedding_provider().await {
let info = provider.info();
println!("Using {} ({})", info.name, info.model);
let embedding = provider.generate_embedding("Hello world").await?;
println!("Dimensions: {}", embedding.len());
}Re-exports§
pub use config::get_embedding_settings;pub use config::is_embeddings_enabled;pub use config::resolve_hf_model;pub use config::resolve_hf_token;pub use config::resolve_ollama_endpoint;pub use config::resolve_ollama_model;pub use config::reset_embedding_settings;pub use config::save_embedding_settings;pub use factory::create_embedding_provider;pub use factory::create_huggingface_provider;pub use factory::create_ollama_provider;pub use factory::detect_available_providers;pub use factory::ProviderDetection;pub use huggingface::HuggingFaceProvider;pub use model2vec::Model2VecProvider;pub use ollama::OllamaProvider;pub use provider::BoxedProvider;pub use provider::EmbeddingProvider;pub use types::EmbeddingProviderType;pub use types::EmbeddingResult;pub use types::EmbeddingSettings;pub use types::ModelConfig;pub use types::ProviderInfo;pub use types::SaveContextConfig;pub use types::SearchMode;pub use types::TieredEmbeddingSettings;pub use types::model2vec_models;pub use chunking::chunk_text;pub use chunking::prepare_item_text;pub use chunking::ChunkConfig;pub use chunking::TextChunk;
Modules§
- chunking
- Text chunking for embeddings.
- config
- Embedding configuration management.
- factory
- Embedding provider factory.
- huggingface
- HuggingFace Inference API embedding provider.
- model2vec
- Model2Vec embedding provider.
- ollama
- Ollama embedding provider.
- provider
- Embedding provider trait.
- types
- Embedding types and configuration.