feat: pass IndexConfig to repositories with scalability options

This commit is contained in:
ochan.kwon
2026-04-16 15:12:42 +09:00
committed by lyingbug
parent 7bd36bf954
commit 927d3debff
14 changed files with 673 additions and 69 deletions
+19 -1
View File
@@ -2,6 +2,7 @@ package service
import (
"context"
"fmt"
"os"
"time"
@@ -44,6 +45,11 @@ func (s *vectorStoreService) CreateStore(ctx context.Context, store *types.Vecto
return err
}
// 2.5. Index config validation (bounds, name characters)
if err := types.ValidateIndexConfig(store.IndexConfig); err != nil {
return err
}
// 3. Duplicate check — DB stores
endpoint := store.ConnectionConfig.GetEndpoint()
indexName := store.IndexConfig.GetIndexNameOrDefault(store.EngineType)
@@ -66,7 +72,19 @@ func (s *vectorStoreService) CreateStore(ctx context.Context, store *types.Vecto
}
}
// 5. Persist
// 5. Auto-detect server version via connection test.
// This is required for engines where the version determines the SDK (e.g., ES v7 vs v8).
// Without it, the wrong SDK may be used causing protocol errors (406, etc.).
version, err := s.TestConnection(ctx, store.EngineType, store.ConnectionConfig)
if err != nil {
return errors.NewBadRequestError(
fmt.Sprintf("connection test failed: %s. Ensure the server is reachable before saving.", err.Error()))
}
if version != "" {
store.ConnectionConfig.Version = version
}
// 6. Persist
logger.Infof(ctx, "Creating vector store: tenant=%d, name=%s, engine=%s",
store.TenantID, secutils.SanitizeForLog(store.Name), store.EngineType)
if err := s.repo.Create(ctx, store); err != nil {
@@ -389,15 +389,14 @@ func TestCreateStore_DifferentEndpointSameIndex_Allowed(t *testing.T) {
repo := &mockVectorStoreRepo{existsByEndpoint: false}
svc := NewVectorStoreService(repo, nil, nil)
// Use postgres with UseDefaultConnection to avoid needing a real ES endpoint.
// The test verifies duplicate-check logic, not connectivity.
store := &types.VectorStore{
TenantID: 1,
Name: "new-store",
EngineType: types.ElasticsearchRetrieverEngineType,
EngineType: types.PostgresRetrieverEngineType,
ConnectionConfig: types.ConnectionConfig{
Addr: "http://es-new:9200",
},
IndexConfig: types.IndexConfig{
IndexName: "shared_index",
UseDefaultConnection: true,
},
}