mirror of
https://github.com/lukaszraczylo/claude-mnemonic.git
synced 2026-06-23 03:51:31 +00:00
refactor(embedding): drop init(), build default registry eagerly
Replace the import-time init() that mutated the DefaultRegistry global with a constructor that returns a ready registry, removing mutate-after-init global state. Exported API unchanged.
This commit is contained in:
@@ -138,7 +138,25 @@ func (r *ModelRegistry) List() []ModelMetadata {
|
||||
}
|
||||
|
||||
// DefaultRegistry is the global model registry with all available models.
|
||||
var DefaultRegistry = NewModelRegistry()
|
||||
// It is constructed eagerly at package load via newDefaultRegistry, which
|
||||
// registers the built-in BGE model — replacing the previous init()-based
|
||||
// mutate-after-init pattern while preserving identical behaviour.
|
||||
var DefaultRegistry = newDefaultRegistry()
|
||||
|
||||
// newDefaultRegistry builds a model registry pre-populated with the built-in
|
||||
// models (currently BGE). Registering at construction time keeps DefaultRegistry
|
||||
// ready-to-use without a separate init() mutating it after package load.
|
||||
func newDefaultRegistry() *ModelRegistry {
|
||||
r := NewModelRegistry()
|
||||
r.Register(ModelMetadata{
|
||||
Name: BGEModelName,
|
||||
Version: BGEModelVersion,
|
||||
Dimensions: EmbeddingDim,
|
||||
Description: "High-quality semantic search model",
|
||||
Default: true,
|
||||
}, newBGEModel)
|
||||
return r
|
||||
}
|
||||
|
||||
// RegisterModel adds a model to the default registry.
|
||||
func RegisterModel(meta ModelMetadata, factory ModelFactory) {
|
||||
|
||||
@@ -562,17 +562,6 @@ func (m *bgeModel) Close() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Register the BGE model with the default registry at init time
|
||||
func init() {
|
||||
RegisterModel(ModelMetadata{
|
||||
Name: BGEModelName,
|
||||
Version: BGEModelVersion,
|
||||
Dimensions: EmbeddingDim,
|
||||
Description: "High-quality semantic search model",
|
||||
Default: true,
|
||||
}, newBGEModel)
|
||||
}
|
||||
|
||||
// Service provides thread-safe text embedding generation with model abstraction.
|
||||
type Service struct {
|
||||
model EmbeddingModel
|
||||
|
||||
Reference in New Issue
Block a user