Skip to content

Commit e83bf51

Browse files
committed
fix(collections): handle errors from LocalRecall constructors
LocalRecall's NewPersistent{Chrome,LocalAI,Postgres}Collection now return errors instead of os.Exit'ing on init failure. Bump the dep and update newVectorEngine to consume the new signatures, surfacing failures as a nil collection (the existing "engine misconfigured" code path) instead of letting the upstream os.Exit kill the embedding process. Without this, a transient embedding-service or PostgreSQL outage during lazy RAG init would crash any long-running host (e.g. the LocalAI distributed orchestrator) instead of degrading to "no RAG available". RAGProviderFromState already handles a nil collection from EnsureCollection by returning (nil, nil, false) to the agent pool, which is the same path agents take when no RAG is configured — so callers upstream need no further change. Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
1 parent 3369136 commit e83bf51

3 files changed

Lines changed: 21 additions & 6 deletions

File tree

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ require (
1818
github.com/jung-kurt/gofpdf v1.16.2
1919
github.com/modelcontextprotocol/go-sdk v1.2.0
2020
github.com/mudler/cogito v0.9.5-0.20260315222927-63abdec7189b
21-
github.com/mudler/localrecall v0.5.9-0.20260415164846-8ad831f840fc
21+
github.com/mudler/localrecall v0.5.10-0.20260504162944-6138c1f535ab
2222
github.com/mudler/skillserver v0.0.5-0.20260221145827-0639a82c8f49
2323
github.com/mudler/xlog v0.0.5
2424
github.com/onsi/ginkgo/v2 v2.27.5

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -299,8 +299,8 @@ github.com/mschoch/smat v0.2.0 h1:8imxQsjDm8yFEAVBe7azKmKSgzSkZXDuKkSq9374khM=
299299
github.com/mschoch/smat v0.2.0/go.mod h1:kc9mz7DoBKqDyiRL7VZN8KvXQMWeTaVnttLRXOlotKw=
300300
github.com/mudler/cogito v0.9.5-0.20260315222927-63abdec7189b h1:A74T2Lauvg61KodYqsjTYDY05kPLcW+efVZjd23dghU=
301301
github.com/mudler/cogito v0.9.5-0.20260315222927-63abdec7189b/go.mod h1:6sfja3lcu2nWRzEc0wwqGNu/eCG3EWgij+8s7xyUeQ4=
302-
github.com/mudler/localrecall v0.5.9-0.20260415164846-8ad831f840fc h1:p1ucQ2rbU4mhG2Xl1Emg5Q6QCYCjI+fvMF9KTek/+sY=
303-
github.com/mudler/localrecall v0.5.9-0.20260415164846-8ad831f840fc/go.mod h1:xuPtgL9zUyiQLmspYzO3kaboYrGbWmwi8BQPt1aCAcs=
302+
github.com/mudler/localrecall v0.5.10-0.20260504162944-6138c1f535ab h1:U6MWVv9Xgb56JTIL4DfsZftSig/LeJA+yizlyw8fq24=
303+
github.com/mudler/localrecall v0.5.10-0.20260504162944-6138c1f535ab/go.mod h1:xuPtgL9zUyiQLmspYzO3kaboYrGbWmwi8BQPt1aCAcs=
304304
github.com/mudler/skillserver v0.0.5-0.20260221145827-0639a82c8f49 h1:dAF1ALXqqapRZo80x56BIBBcPrPbRNerbd66rdyO8J4=
305305
github.com/mudler/skillserver v0.0.5-0.20260221145827-0639a82c8f49/go.mod h1:z3yFhcL9bSykmmh6xgGu0hyoItd4CnxgtWMEWw8uFJU=
306306
github.com/mudler/xlog v0.0.5 h1:2unBuVC5rNGhCC86UaA94TElWFml80NL5XLK+kAmNuU=

webui/collections/inprocess.go

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,30 +13,45 @@ import (
1313
"github.com/sashabaranov/go-openai"
1414
)
1515

16+
// newVectorEngine creates the underlying RAG store for a collection.
17+
// Returns nil + logs on failure (engine misconfiguration or transient embedding/DB
18+
// outage). Callers must check for nil — RAG init failures must not crash the
19+
// embedding application; LocalRecall used to os.Exit on these errors but now
20+
// returns them, and we surface that to callers as a nil collection.
1621
func newVectorEngine(
1722
vectorEngineType string,
1823
llmClient *openai.Client,
1924
apiURL, apiKey, collectionName, dbPath, fileAssets, embeddingModel, databaseURL string,
2025
maxChunkSize, chunkOverlap int,
2126
) *rag.PersistentKB {
27+
var (
28+
kb *rag.PersistentKB
29+
err error
30+
)
2231
switch vectorEngineType {
2332
case "chromem":
2433
xlog.Info("Chromem collection", "collectionName", collectionName, "dbPath", dbPath)
25-
return rag.NewPersistentChromeCollection(llmClient, collectionName, dbPath, fileAssets, embeddingModel, maxChunkSize, chunkOverlap)
34+
kb, err = rag.NewPersistentChromeCollection(llmClient, collectionName, dbPath, fileAssets, embeddingModel, maxChunkSize, chunkOverlap)
2635
case "localai":
2736
xlog.Info("LocalAI collection", "collectionName", collectionName, "apiURL", apiURL)
28-
return rag.NewPersistentLocalAICollection(llmClient, apiURL, apiKey, collectionName, dbPath, fileAssets, embeddingModel, maxChunkSize, chunkOverlap)
37+
kb, err = rag.NewPersistentLocalAICollection(llmClient, apiURL, apiKey, collectionName, dbPath, fileAssets, embeddingModel, maxChunkSize, chunkOverlap)
2938
case "postgres":
3039
if databaseURL == "" {
3140
xlog.Error("DATABASE_URL is required for PostgreSQL engine")
3241
return nil
3342
}
3443
xlog.Info("PostgreSQL collection", "collectionName", collectionName, "databaseURL", databaseURL)
35-
return rag.NewPersistentPostgresCollection(llmClient, collectionName, dbPath, fileAssets, embeddingModel, maxChunkSize, chunkOverlap, databaseURL)
44+
kb, err = rag.NewPersistentPostgresCollection(llmClient, collectionName, dbPath, fileAssets, embeddingModel, maxChunkSize, chunkOverlap, databaseURL)
3645
default:
3746
xlog.Error("Unknown vector engine", "engine", vectorEngineType)
3847
return nil
3948
}
49+
if err != nil {
50+
xlog.Error("Failed to create vector engine collection",
51+
"engine", vectorEngineType, "collection", collectionName, "error", err)
52+
return nil
53+
}
54+
return kb
4055
}
4156

4257
// backendInProcess implements Backend using in-process state.

0 commit comments

Comments
 (0)