From bcc6e142fa3cd7b408f766204bff1e214c710305 Mon Sep 17 00:00:00 2001 From: Acbox Date: Fri, 6 Feb 2026 20:33:29 +0800 Subject: [PATCH] fix: drop sql & qdrant --- db/migrations/0001_init.down.sql | 9 +++--- internal/memory/qdrant_store.go | 54 ++++++++++++++++++++++++++------ scripts/db-drop.sh | 0 scripts/db-up.sh | 0 4 files changed, 50 insertions(+), 13 deletions(-) mode change 100644 => 100755 scripts/db-drop.sh mode change 100644 => 100755 scripts/db-up.sh diff --git a/db/migrations/0001_init.down.sql b/db/migrations/0001_init.down.sql index 7ce16393..687bea5b 100644 --- a/db/migrations/0001_init.down.sql +++ b/db/migrations/0001_init.down.sql @@ -8,7 +8,6 @@ DROP TABLE IF EXISTS containers; DROP TABLE IF EXISTS channel_sessions; DROP TABLE IF EXISTS contact_channels; DROP TABLE IF EXISTS bot_preauth_keys; -DROP TABLE IF EXISTS contacts; DROP TABLE IF EXISTS bot_channel_configs; DROP TABLE IF EXISTS user_channel_bindings; DROP TABLE IF EXISTS history; @@ -16,9 +15,11 @@ DROP TABLE IF EXISTS conversations; DROP TABLE IF EXISTS bot_model_configs; DROP TABLE IF EXISTS bot_settings; DROP TABLE IF EXISTS bot_members; +DROP TABLE IF EXISTS contact_bind_tokens; DROP TABLE IF EXISTS bots; -DROP TABLE IF EXISTS model_variants; -DROP TABLE IF EXISTS models; -DROP TABLE IF EXISTS llm_providers; DROP TABLE IF EXISTS users; +DROP TABLE IF EXISTS contacts; +-- DROP TABLE IF EXISTS model_variants; +-- DROP TABLE IF EXISTS models; +-- DROP TABLE IF EXISTS llm_providers; DROP TYPE IF EXISTS user_role; diff --git a/internal/memory/qdrant_store.go b/internal/memory/qdrant_store.go index f9c3d376..ce5a826e 100644 --- a/internal/memory/qdrant_store.go +++ b/internal/memory/qdrant_store.go @@ -10,6 +10,8 @@ import ( "time" "github.com/qdrant/go-client/qdrant" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/status" ) const ( @@ -32,12 +34,12 @@ type QdrantStore struct { } type qdrantPoint struct { - ID string `json:"id"` - Vector []float32 `json:"vector"` - VectorName string `json:"vector_name,omitempty"` - SparseIndices []uint32 `json:"sparse_indices,omitempty"` - SparseValues []float32 `json:"sparse_values,omitempty"` - SparseVectorName string `json:"sparse_vector_name,omitempty"` + ID string `json:"id"` + Vector []float32 `json:"vector"` + VectorName string `json:"vector_name,omitempty"` + SparseIndices []uint32 `json:"sparse_indices,omitempty"` + SparseValues []float32 `json:"sparse_values,omitempty"` + SparseVectorName string `json:"sparse_vector_name,omitempty"` Payload map[string]any `json:"payload,omitempty"` } @@ -396,7 +398,10 @@ func (s *QdrantStore) ensureCollection(ctx context.Context, vectors map[string]i return err } if exists { - return s.refreshCollectionSchema(ctx, vectors) + if err := s.refreshCollectionSchema(ctx, vectors); err != nil { + return err + } + return s.ensurePayloadIndexes(ctx) } var vectorsConfig *qdrant.VectorsConfig if len(vectors) > 0 { @@ -421,11 +426,14 @@ func (s *QdrantStore) ensureCollection(ctx context.Context, vectors map[string]i sparseVocabVectorName: {Modifier: qdrant.PtrOf(qdrant.Modifier_None)}, }) } - return s.client.CreateCollection(ctx, &qdrant.CreateCollection{ + if err := s.client.CreateCollection(ctx, &qdrant.CreateCollection{ CollectionName: s.collection, VectorsConfig: vectorsConfig, SparseVectorsConfig: sparseConfig, - }) + }); err != nil { + return err + } + return s.ensurePayloadIndexes(ctx) } func (s *QdrantStore) refreshCollectionSchema(ctx context.Context, vectors map[string]int) error { @@ -494,6 +502,34 @@ sparseCheck: return nil } +func (s *QdrantStore) ensurePayloadIndexes(ctx context.Context) error { + if s.client == nil { + return nil + } + fields := []string{"botId", "sessionId", "runId"} + wait := true + for _, field := range fields { + _, err := s.client.CreateFieldIndex(ctx, &qdrant.CreateFieldIndexCollection{ + CollectionName: s.collection, + FieldName: field, + FieldType: qdrant.FieldType_FieldTypeKeyword.Enum(), + Wait: &wait, + }) + if err == nil { + continue + } + if status.Code(err) == codes.AlreadyExists { + continue + } + // Fall back to string match when the backend wraps the error. + if strings.Contains(strings.ToLower(err.Error()), "already exists") { + continue + } + return err + } + return nil +} + func (s *QdrantStore) ensureSparseVectors(ctx context.Context) error { if s.sparseVectorName == "" { return nil diff --git a/scripts/db-drop.sh b/scripts/db-drop.sh old mode 100644 new mode 100755 diff --git a/scripts/db-up.sh b/scripts/db-up.sh old mode 100644 new mode 100755