Open-source LLM knowledge platform: turn raw documents into a queryable RAG, an autonomous reasoning agent, and a self-maintaining Wiki.
Go agentagenticaichatbotdsh-pluginembeddingsevaluationgenerative-aigolangknowledge-basellmmulti-tenantollamaopenaiquestion-answeringragrerankingsemantic-searchvector-searchwiki
feat(database): update database initialization to conditionally handle embeddings
majian3cc576a4933b
diff --git a/go.mod b/go.modindex d3f87e5b4..988d5c95a 100644--- a/go.mod+++ b/go.mod@@ -10,7 +10,7 @@ require (github.com/elastic/go-elasticsearch/v7 v7.17.10github.com/elastic/go-elasticsearch/v8 v8.18.0github.com/gin-contrib/cors v1.7.5- github.com/gin-gonic/gin v1.10.0+ github.com/gin-gonic/gin v1.11.0github.com/go-viper/mapstructure/v2 v2.2.1github.com/golang-jwt/jwt/v5 v5.3.0github.com/golang-migrate/migrate/v4 v4.19.0@@ -51,32 +51,33 @@ require (github.com/andybalholm/cascadia v1.3.3 // indirectgithub.com/bahlo/generic-list-go v0.2.0 // indirectgithub.com/buger/jsonparser v1.1.1 // indirect- github.com/bytedance/sonic v1.13.2 // indirect- github.com/bytedance/sonic/loader v0.2.4 // indirect+ github.com/bytedance/sonic v1.14.0 // indirect+ github.com/bytedance/sonic/loader v0.3.0 // indirectgithub.com/cenkalti/backoff/v5 v5.0.2 // indirectgithub.com/cespare/xxhash/v2 v2.3.0 // indirectgithub.com/chromedp/cdproto v0.0.0-20250724212937-08a3db8b4327 // indirectgithub.com/chromedp/sysutil v1.1.0 // indirectgithub.com/clbanning/mxj v1.8.4 // indirect- github.com/cloudwego/base64x v0.1.5 // indirect+ github.com/cloudwego/base64x v0.1.6 // indirectgithub.com/davecgh/go-spew v1.1.1 // indirectgithub.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirectgithub.com/dustin/go-humanize v1.0.1 // indirectgithub.com/elastic/elastic-transport-go/v8 v8.7.0 // indirectgithub.com/fsnotify/fsnotify v1.8.0 // indirectgithub.com/gabriel-vasile/mimetype v1.4.8 // indirect- github.com/gin-contrib/sse v1.0.0 // indirect+ github.com/gin-contrib/sse v1.1.0 // indirectgithub.com/go-ini/ini v1.67.0 // indirectgithub.com/go-json-experiment/json v0.0.0-20250725192818-e39067aee2d2 // indirectgithub.com/go-logr/logr v1.4.3 // indirectgithub.com/go-logr/stdr v1.2.2 // indirectgithub.com/go-playground/locales v0.14.1 // indirectgithub.com/go-playground/universal-translator v0.18.1 // indirect- github.com/go-playground/validator/v10 v10.26.0 // indirect+ github.com/go-playground/validator/v10 v10.27.0 // indirectgithub.com/gobwas/httphead v0.1.0 // indirectgithub.com/gobwas/pool v0.2.1 // indirectgithub.com/gobwas/ws v1.4.0 // indirectgithub.com/goccy/go-json v0.10.5 // indirect+ github.com/goccy/go-yaml v1.18.0 // indirectgithub.com/google/go-querystring v1.1.0 // indirectgithub.com/grpc-ecosystem/grpc-gateway/v2 v2.27.1 // indirectgithub.com/hashicorp/errwrap v1.1.0 // indirect@@ -90,7 +91,7 @@ require (github.com/jinzhu/now v1.1.5 // indirectgithub.com/json-iterator/go v1.1.12 // indirectgithub.com/klauspost/compress v1.18.1 // indirect- github.com/klauspost/cpuid/v2 v2.2.10 // indirect+ github.com/klauspost/cpuid/v2 v2.3.0 // indirectgithub.com/leodido/go-urn v1.4.0 // indirectgithub.com/lib/pq v1.10.9 // indirectgithub.com/mailru/easyjson v0.9.0 // indirect@@ -103,9 +104,11 @@ require (github.com/modern-go/reflect2 v1.0.2 // indirectgithub.com/mozillazg/go-httpheader v0.2.1 // indirectgithub.com/olekukonko/tablewriter v0.0.5 // indirect- github.com/pelletier/go-toml/v2 v2.2.3 // indirect+ github.com/pelletier/go-toml/v2 v2.2.4 // indirectgithub.com/pierrec/lz4/v4 v4.1.21 // indirectgithub.com/pmezard/go-difflib v1.0.0 // indirect+ github.com/quic-go/qpack v0.5.1 // indirect+ github.com/quic-go/quic-go v0.54.0 // indirectgithub.com/rivo/uniseg v0.4.7 // indirectgithub.com/robfig/cron/v3 v3.0.1 // indirectgithub.com/rs/xid v1.6.0 // indirect@@ -116,18 +119,21 @@ require (github.com/spf13/pflag v1.0.6 // indirectgithub.com/subosito/gotenv v1.6.0 // indirectgithub.com/twitchyliquid64/golang-asm v0.15.1 // indirect- github.com/ugorji/go/codec v1.2.12 // indirect+ github.com/ugorji/go/codec v1.3.0 // indirectgithub.com/wk8/go-ordered-map/v2 v2.1.8 // indirectgithub.com/yosida95/uritemplate/v3 v3.0.2 // indirectgo.opentelemetry.io/auto/sdk v1.2.1 // indirectgo.opentelemetry.io/otel/metric v1.38.0 // indirectgo.opentelemetry.io/proto/otlp v1.7.0 // indirect+ go.uber.org/mock v0.5.0 // indirectgo.uber.org/multierr v1.11.0 // indirect- golang.org/x/arch v0.15.0 // indirect+ golang.org/x/arch v0.20.0 // indirect+ golang.org/x/mod v0.29.0 // indirectgolang.org/x/net v0.47.0 // indirectgolang.org/x/sys v0.38.0 // indirectgolang.org/x/text v0.31.0 // indirectgolang.org/x/time v0.14.0 // indirect+ golang.org/x/tools v0.38.0 // indirectgoogle.golang.org/genproto/googleapis/api v0.0.0-20250804133106-a7a43d27e69b // indirectgoogle.golang.org/genproto/googleapis/rpc v0.0.0-20251111163417-95abcf5c77ba // indirectgopkg.in/yaml.v3 v3.0.1 // indirectdiff --git a/go.sum b/go.sumindex c567e3118..bbe798f0e 100644--- a/go.sum+++ b/go.sum@@ -19,11 +19,10 @@ github.com/bsm/gomega v1.27.10 h1:yeMWxP2pV2fG3FgAODIY8EiRE3dy0aeFYt4l7wh6yKA=github.com/bsm/gomega v1.27.10/go.mod h1:JyEr/xRbxbtgWNi8tIEVPUYZ5Dzef52k01W3YH0H+O0=github.com/buger/jsonparser v1.1.1 h1:2PnMjfWD7wBILjqQbt530v576A/cAbQvEW9gGIpYMUs=github.com/buger/jsonparser v1.1.1/go.mod h1:6RYKKt7H4d4+iWqouImQ9R2FZql3VbhNgx27UK13J/0=-github.com/bytedance/sonic v1.13.2 h1:8/H1FempDZqC4VqjptGo14QQlJx8VdZJegxs6wwfqpQ=-github.com/bytedance/sonic v1.13.2/go.mod h1:o68xyaF9u2gvVBuGHPlUVCy+ZfmNNO5ETf1+KgkJhz4=-github.com/bytedance/sonic/loader v0.1.1/go.mod h1:ncP89zfokxS5LZrJxl5z0UJcsk4M4yY2JpfqGeCtNLU=-github.com/bytedance/sonic/loader v0.2.4 h1:ZWCw4stuXUsn1/+zQDqeE7JKP+QO47tz7QCNan80NzY=-github.com/bytedance/sonic/loader v0.2.4/go.mod h1:N8A3vUdtUebEY2/VQC0MyhYeKUFosQU6FxH2JmUe6VI=+github.com/bytedance/sonic v1.14.0 h1:/OfKt8HFw0kh2rj8N0F6C/qPGRESq0BbaNZgcNXXzQQ=+github.com/bytedance/sonic v1.14.0/go.mod h1:WoEbx8WTcFJfzCe0hbmyTGrfjt8PzNEBdxlNUO24NhA=+github.com/bytedance/sonic/loader v0.3.0 h1:dskwH8edlzNMctoruo8FPTJDF3vLtDT0sXZwvZJyqeA=+github.com/bytedance/sonic/loader v0.3.0/go.mod h1:N8A3vUdtUebEY2/VQC0MyhYeKUFosQU6FxH2JmUe6VI=github.com/cenkalti/backoff/v5 v5.0.2 h1:rIfFVxEf1QsI7E1ZHfp/B4DF/6QBAUhmgkxc0H7Zss8=github.com/cenkalti/backoff/v5 v5.0.2/go.mod h1:rkhZdG3JZukswDf7f0cwqPNk4K0sa+F97BxZthm/crw=github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs=@@ -36,9 +35,8 @@ github.com/chromedp/sysutil v1.1.0 h1:PUFNv5EcprjqXZD9nJb9b/c9ibAbxiYo4exNWZyipwgithub.com/chromedp/sysutil v1.1.0/go.mod h1:WiThHUdltqCNKGc4gaU50XgYjwjYIhKWoHGPTUfWTJ8=github.com/clbanning/mxj v1.8.4 h1:HuhwZtbyvyOw+3Z1AowPkU87JkJUSv751ELWaiTpj8I=github.com/clbanning/mxj v1.8.4/go.mod h1:BVjHeAH+rl9rs6f+QIpeRl0tfu10SXn1pUSa5PVGJng=-github.com/cloudwego/base64x v0.1.5 h1:XPciSp1xaq2VCSt6lF0phncD4koWyULpl5bUxbfCyP4=-github.com/cloudwego/base64x v0.1.5/go.mod h1:0zlkT4Wn5C6NdauXdJRhSKRlJvmclQ1hhJgA0rcu/8w=-github.com/cloudwego/iasm v0.2.0/go.mod h1:8rXZaNYT2n95jn+zTI1sDr+IgcD2GVs0nlbbQPiEFhY=+github.com/cloudwego/base64x v0.1.6 h1:t11wG9AECkCDk5fMSoxmufanudBtJ+/HemLstXDLI2M=+github.com/cloudwego/base64x v0.1.6/go.mod h1:OFcloc187FXDaYHvrNIjxSe8ncn0OOM8gEHfghB2IPU=github.com/containerd/errdefs v1.0.0 h1:tg5yIfIlQIrxYtu9ajqY42W3lpS19XqdxRQeEwYG8PI=github.com/containerd/errdefs v1.0.0/go.mod h1:+YBYIdtsnF4Iw6nWZhJcqGSg/dwvV7tyJ/kCkyJ2k+M=github.com/containerd/errdefs/pkg v0.3.0 h1:9IKJ06FvyNlexW690DXuQNx2KA2cUJXx151Xdx3ZPPE=@@ -76,10 +74,10 @@ github.com/gabriel-vasile/mimetype v1.4.8 h1:FfZ3gj38NjllZIeJAmMhr+qKL8Wu+nOoI3Ggithub.com/gabriel-vasile/mimetype v1.4.8/go.mod h1:ByKUIKGjh1ODkGM1asKUbQZOLGrPjydw3hYPU2YU9t8=github.com/gin-contrib/cors v1.7.5 h1:cXC9SmofOrRg0w9PigwGlHG3ztswH6bqq4vJVXnvYMk=github.com/gin-contrib/cors v1.7.5/go.mod h1:4q3yi7xBEDDWKapjT2o1V7mScKDDr8k+jZ0fSquGoy0=-github.com/gin-contrib/sse v1.0.0 h1:y3bT1mUWUxDpW4JLQg/HnTqV4rozuW4tC9eFKTxYI9E=-github.com/gin-contrib/sse v1.0.0/go.mod h1:zNuFdwarAygJBht0NTKiSi3jRf6RbqeILZ9Sp6Slhe0=-github.com/gin-gonic/gin v1.10.0 h1:nTuyha1TYqgedzytsKYqna+DfLos46nTv2ygFy86HFU=-github.com/gin-gonic/gin v1.10.0/go.mod h1:4PMNQiOhvDRa013RKVbsiNwoyezlm2rm0uX/T7kzp5Y=+github.com/gin-contrib/sse v1.1.0 h1:n0w2GMuUpWDVp7qSpvze6fAu9iRxJY4Hmj6AmBOU05w=+github.com/gin-contrib/sse v1.1.0/go.mod h1:hxRZ5gVpWMT7Z0B0gSNYqqsSCNIJMjzvm6fqCz9vjwM=+github.com/gin-gonic/gin v1.11.0 h1:OW/6PLjyusp2PPXtyxKHU0RbX6I/l28FTdDlae5ueWk=+github.com/gin-gonic/gin v1.11.0/go.mod h1:+iq/FyxlGzII0KHiBGjuNn4UNENUlKbGlNmc+W50Dls=github.com/go-ini/ini v1.67.0 h1:z6ZrTEZqSWOTyH2FlglNbNgARyHG8oLW9gMELqKr06A=github.com/go-ini/ini v1.67.0/go.mod h1:ByCAeIL28uOIIG0E3PJtZPDL8WnHpFKFOtgjp+3Ies8=github.com/go-json-experiment/json v0.0.0-20250725192818-e39067aee2d2 h1:iizUGZ9pEquQS5jTGkh4AqeeHCMbfbjeb0zMt0aEFzs=@@ -99,8 +97,8 @@ github.com/go-playground/locales v0.14.1 h1:EWaQ/wswjilfKLTECiXz7Rh+3BjFhfDFKv/ogithub.com/go-playground/locales v0.14.1/go.mod h1:hxrqLVvrK65+Rwrd5Fc6F2O76J/NuW9t0sjnWqG1slY=github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJnYK9S473LQFuzCbDbfSFY=github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY=-github.com/go-playground/validator/v10 v10.26.0 h1:SP05Nqhjcvz81uJaRfEV0YBSSSGMc/iMaVtFbr3Sw2k=-github.com/go-playground/validator/v10 v10.26.0/go.mod h1:I5QpIEbmr8On7W0TktmJAumgzX4CA1XNl4ZmDuVHKKo=+github.com/go-playground/validator/v10 v10.27.0 h1:w8+XrWVMhGkxOaaowyKH35gFydVHOvC0/uWoy2Fzwn4=+github.com/go-playground/validator/v10 v10.27.0/go.mod h1:I5QpIEbmr8On7W0TktmJAumgzX4CA1XNl4ZmDuVHKKo=github.com/go-viper/mapstructure/v2 v2.2.1 h1:ZAaOCxANMuZx5RCeg0mBdEZk7DZasvvZIxtHqx8aGss=github.com/go-viper/mapstructure/v2 v2.2.1/go.mod h1:oJDH3BJKyqBA2TXFhDsKDGDTlndYOZ6rGS0BRZIxGhM=github.com/gobwas/httphead v0.1.0 h1:exrUm0f4YX0L7EBwZHuCF4GDp8aJfVeBrlLQrs6NqWU=@@ -111,6 +109,8 @@ github.com/gobwas/ws v1.4.0 h1:CTaoG1tojrh4ucGPcoJFiAQUAsEWekEWvLy7GsVNqGs=github.com/gobwas/ws v1.4.0/go.mod h1:G3gNqMNtPppf5XUz7O4shetPpcZ1VJ7zt18dlUeakrc=github.com/goccy/go-json v0.10.5 h1:Fq85nIqj+gXn/S5ahsiTlK3TmC85qgirsdTP/+DeaC4=github.com/goccy/go-json v0.10.5/go.mod h1:oq7eo15ShAhp70Anwd5lgX2pLfOS3QCiwU/PULtXL6M=+github.com/goccy/go-yaml v1.18.0 h1:8W7wMFS12Pcas7KU+VVkaiCng+kG8QiFeFwzFb+rwuw=+github.com/goccy/go-yaml v1.18.0/go.mod h1:XBurs7gK8ATbW4ZPGKgcbrY1Br56PdM69F7LkFRi1kA=github.com/golang-jwt/jwt/v5 v5.2.1/go.mod h1:pqrtFR0X4osieyHYxtmOUWsAWrfe1Q5UVIyoH402zdk=github.com/golang-jwt/jwt/v5 v5.3.0 h1:pv4AsKCKKZuqlgs5sUmn4x8UlGa0kEVt/puTpKx9vvo=github.com/golang-jwt/jwt/v5 v5.3.0/go.mod h1:fxCRLWMO43lRc8nhHWY6LGqRcf+1gQWArsqaEUEa5bE=@@ -161,10 +161,8 @@ github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmgithub.com/klauspost/compress v1.18.1 h1:bcSGx7UbpBqMChDtsF28Lw6v/G94LPrrbMbdC3JH2co=github.com/klauspost/compress v1.18.1/go.mod h1:ZQFFVG+MdnR0P+l6wpXgIL4NTtwiKIdBnrBd8Nrxr+0=github.com/klauspost/cpuid/v2 v2.0.1/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg=-github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg=-github.com/klauspost/cpuid/v2 v2.2.10 h1:tBs3QSyvjDyFTq3uoc/9xFpCuOsJQFNPiAhYdw2skhE=-github.com/klauspost/cpuid/v2 v2.2.10/go.mod h1:hqwkgyIinND0mEev00jJYCxPNVRVXFQeu1XKlok6oO0=-github.com/knz/go-libedit v1.10.1/go.mod h1:MZTVkCWyz0oBc7JOWP3wNAzd002ZbM/5hgShxwh4x8M=+github.com/klauspost/cpuid/v2 v2.3.0 h1:S4CRMLnYUhGeDFDqkGriYKdfoFlDnMtqTiI/sFzhA9Y=+github.com/klauspost/cpuid/v2 v2.3.0/go.mod h1:hqwkgyIinND0mEev00jJYCxPNVRVXFQeu1XKlok6oO0=github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=@@ -221,8 +219,8 @@ github.com/panjf2000/ants/v2 v2.11.2 h1:AVGpMSePxUNpcLaBO34xuIgM1ZdKOiGnpxLXixLigithub.com/panjf2000/ants/v2 v2.11.2/go.mod h1:8u92CYMUc6gyvTIw8Ru7Mt7+/ESnJahz5EVtqfrilek=github.com/parquet-go/parquet-go v0.25.0 h1:GwKy11MuF+al/lV6nUsFw8w8HCiPOSAx1/y8yFxjH5c=github.com/parquet-go/parquet-go v0.25.0/go.mod h1:OqBBRGBl7+llplCvDMql8dEKaDqjaFA/VAPw+OJiNiw=-github.com/pelletier/go-toml/v2 v2.2.3 h1:YmeHyLY8mFWbdkNWwpr+qIL2bEqT0o95WSdkNHvL12M=-github.com/pelletier/go-toml/v2 v2.2.3/go.mod h1:MfCQTFTvCcUyyvvwm1+G6H/jORL20Xlb6rzQu9GuUkc=+github.com/pelletier/go-toml/v2 v2.2.4 h1:mye9XuhQ6gvn5h28+VilKrrPoQVanw5PMw/TB0t5Ec4=+github.com/pelletier/go-toml/v2 v2.2.4/go.mod h1:2gIqNv+qfxSVS7cM2xJQKtLSTLUE9V8t9Stt+h56mCY=github.com/pgvector/pgvector-go v0.3.0 h1:Ij+Yt78R//uYqs3Zk35evZFvr+G0blW0OUN+Q2D1RWc=github.com/pgvector/pgvector-go v0.3.0/go.mod h1:duFy+PXWfW7QQd5ibqutBO4GxLsUZ9RVXhFZGIBsWSA=github.com/pierrec/lz4/v4 v4.1.21 h1:yOVMLb6qSIDP67pl/5F7RepeKYu/VmTyEXvuMI5d9mQ=@@ -233,6 +231,10 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbgithub.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=github.com/qdrant/go-client v1.16.1 h1:Jr47kz0k8I+U2sUm2UUO2eq2kL0fTcgjLPIz6a0RKuQ=github.com/qdrant/go-client v1.16.1/go.mod h1:I+EL3h4HRoRTeHtbfOd/4kDXwCukZfkd41j/9wryGkw=+github.com/quic-go/qpack v0.5.1 h1:giqksBPnT/HDtZ6VhtFKgoLOWmlyo9Ei6u9PqzIMbhI=+github.com/quic-go/qpack v0.5.1/go.mod h1:+PC4XFrEskIVkcLzpEkbLqq1uCoxPhQuvK5rH1ZgaEg=+github.com/quic-go/quic-go v0.54.0 h1:6s1YB9QotYI6Ospeiguknbp2Znb/jZYjZLRXn9kMQBg=+github.com/quic-go/quic-go v0.54.0/go.mod h1:e68ZEaCdyviluZmy44P6Iey98v/Wfz6HCjQEm+l8zTY=github.com/redis/go-redis/v9 v9.14.0 h1:u4tNCjXOyzfgeLN+vAZaW1xUooqWDqVEsZN0U01jfAE=github.com/redis/go-redis/v9 v9.14.0/go.mod h1:huWgSWd8mW6+m0VPhJjSSQ+d6Nh1VICQ6Q5lHuCH/Iw=github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=@@ -263,14 +265,11 @@ github.com/spf13/viper v1.20.1/go.mod h1:P9Mdzt1zoHIG8m2eZQinpiBjo6kCmZSKBClNNqjgithub.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=-github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA=github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=-github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=-github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U=github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U=github.com/subosito/gotenv v1.6.0 h1:9NlTDc1FTs4qu0DDq7AEtTPNw6SVm7uBMsUCUjABIf8=@@ -283,8 +282,8 @@ github.com/tmthrgd/go-hex v0.0.0-20190904060850-447a3041c3bc h1:9lRDQMhESg+zvGYmgithub.com/tmthrgd/go-hex v0.0.0-20190904060850-447a3041c3bc/go.mod h1:bciPuU6GHm1iF1pBvUfxfsH0Wmnc2VbpgvbI9ZWuIRs=github.com/twitchyliquid64/golang-asm v0.15.1 h1:SU5vSMR7hnwNxj24w34ZyCi/FmDZTkS4MhqMhdFk5YI=github.com/twitchyliquid64/golang-asm v0.15.1/go.mod h1:a1lVb/DtPvCB8fslRZhAngC2+aY1QWCk3Cedj/Gdt08=-github.com/ugorji/go/codec v1.2.12 h1:9LC83zGrHhuUA9l16C9AHXAqEV/2wBQ4nkvumAE65EE=-github.com/ugorji/go/codec v1.2.12/go.mod h1:UNopzCgEMSXjBc6AOMqYvWC1ktqTAfzJZUZgYf6w6lg=+github.com/ugorji/go/codec v1.3.0 h1:Qd2W2sQawAfG8XSvzwhBeoGq71zXOC/Q1E9y/wUcsUA=+github.com/ugorji/go/codec v1.3.0/go.mod h1:pRBVtBSKl77K30Bv8R2P+cLSGaTtex6fsA2Wjqmfxj4=github.com/uptrace/bun v1.1.12 h1:sOjDVHxNTuM6dNGaba0wUuz7KvDE1BmNu9Gqs2gJSXQ=github.com/uptrace/bun v1.1.12/go.mod h1:NPG6JGULBeQ9IU6yHp7YGELRa5Agmd7ATZdz4tGZ6z0=github.com/uptrace/bun/dialect/pgdialect v1.1.12 h1:m/CM1UfOkoBTglGO5CUTKnIKKOApOYxkcP2qn0F9tJk=@@ -334,10 +333,12 @@ go.uber.org/dig v1.18.1 h1:rLww6NuajVjeQn+49u5NcezUJEGwd5uXmyoCKW2g5Es=go.uber.org/dig v1.18.1/go.mod h1:Us0rSJiThwCv2GteUN0Q7OKvU7n5J4dxZ9JKUXozFdE=go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto=go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE=+go.uber.org/mock v0.5.0 h1:KAMbZvZPyBPWgD14IrIQ38QCyjwpvVVV6K/bHl1IwQU=+go.uber.org/mock v0.5.0/go.mod h1:ge71pBPLYDk7QIi1LupWxdAykm7KIEFchiOqd6z7qMM=go.uber.org/multierr v1.11.0 h1:blXXJkSxSSfBVBlC76pxqeO+LN3aDfLQo+309xJstO0=go.uber.org/multierr v1.11.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y=-golang.org/x/arch v0.15.0 h1:QtOrQd0bTUnhNVNndMpLHNWrDmYzZ2KDqSrEymqInZw=-golang.org/x/arch v0.15.0/go.mod h1:JmwW7aLIoRUKgaTzhkiEFxvcEiQGyOg9BMonBJUS7EE=+golang.org/x/arch v0.20.0 h1:dx1zTU0MAE98U+TQ8BLl7XsJbgze2WnNKF/8tGp/Q6c=+golang.org/x/arch v0.20.0/go.mod h1:bdwinDaKcfZUGpH09BB7ZmOfhalA8lQdzl62l8gGWsk=golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=golang.org/x/crypto v0.13.0/go.mod h1:y6Z2r+Rw4iayiXXAIxJIDAJ1zMW4yaTpebo8fPOliYc=@@ -351,6 +352,8 @@ golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=golang.org/x/mod v0.12.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=golang.org/x/mod v0.15.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=golang.org/x/mod v0.17.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=+golang.org/x/mod v0.29.0 h1:HV8lRxZC4l2cr3Zq1LvtOsi/ThTgWnUk/y64QSs8GwA=+golang.org/x/mod v0.29.0/go.mod h1:NyhrlYXJ2H4eJiRy/WDBO6HMqZQ6q9nk4JzS3NuCK+w=golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=@@ -416,6 +419,8 @@ golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbcgolang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU=golang.org/x/tools v0.13.0/go.mod h1:HvlwmtVNQAhOuCjW7xxvovg8wbNq7LwfXh/k7wXUl58=golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d/go.mod h1:aiJjzUbINMkxbQROHiO6hDPo2LHcIPhhQsa9DLh0yGk=+golang.org/x/tools v0.38.0 h1:Hx2Xv8hISq8Lm16jvBZ2VQf+RLmbd7wVUsALibYI/IQ=+golang.org/x/tools v0.38.0/go.mod h1:yEsQ/d/YK8cjh0L6rZlY8tgtlKiBNTL14pGDJPJpYQs=golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=gonum.org/v1/gonum v0.16.0 h1:5+ul4Swaf3ESvrOnidPp4GZbzf0mxVQpDCYUQE7OJfk=@@ -440,4 +445,3 @@ gorm.io/gorm v1.25.12 h1:I0u8i2hWQItBq1WfE0o2+WuL9+8L21K9e2HHSTE/0f8=gorm.io/gorm v1.25.12/go.mod h1:xh7N7RHfYlNc5EmcI/El95gXusucDrQnHXe0+CgWcLQ=mellium.im/sasl v0.3.1 h1:wE0LW6g7U83vhvxjC1IY8DnXM+EU095yeo8XClvCdfo=mellium.im/sasl v0.3.1/go.mod h1:xm59PUYpZHhgQ9ZqoJ5QaCqzWMi8IeS49dhp6plPCzw=-nullprogram.com/x/optparse v1.0.0/go.mod h1:KdyPE+Igbe0jQUrVfMqDMeJQIJZEuyV7pjYmp6pbG50=diff --git a/internal/container/container.go b/internal/container/container.goindex 425a9594c..0d51acd0f 100644--- a/internal/container/container.go+++ b/internal/container/container.go@@ -253,13 +253,22 @@ func initDatabase(cfg *config.Config) (*gorm.DB, error) {dbPassword := os.Getenv("DB_PASSWORD")encodedPassword := url.QueryEscape(dbPassword)+ // Check if postgres is in RETRIEVE_DRIVER to determine skip_embedding+ retrieveDriver := strings.Split(os.Getenv("RETRIEVE_DRIVER"), ",")+ skipEmbedding := "true"+ if slices.Contains(retrieveDriver, "postgres") {+ skipEmbedding = "false"+ }+ logger.Infof(context.Background(), "Skip embedding: %s", skipEmbedding)+migrateDSN = fmt.Sprintf(- "postgres://%s:%s@%s:%s/%s?sslmode=disable",+ "postgres://%s:%s@%s:%s/%s?sslmode=disable&options=-c%%20app.skip_embedding=%s",os.Getenv("DB_USER"),encodedPassword, // Use encoded passwordos.Getenv("DB_HOST"),os.Getenv("DB_PORT"),os.Getenv("DB_NAME"),+ skipEmbedding,)// Debug log (don't log password)@@ -282,10 +291,15 @@ func initDatabase(cfg *config.Config) (*gorm.DB, error) {// To enable auto-recovery from dirty state, set AUTO_RECOVER_DIRTY=trueif os.Getenv("AUTO_MIGRATE") != "false" {logger.Infof(context.Background(), "Running database migrations...")+autoRecover := os.Getenv("AUTO_RECOVER_DIRTY") == "true"- if err := database.RunMigrationsWithOptions(migrateDSN, database.MigrationOptions{+ migrationOpts := database.MigrationOptions{AutoRecoverDirty: autoRecover,- }); err != nil {+ }++ // Run base migrations (all versioned migrations including embeddings)+ // The embeddings migration will be conditionally executed based on skip_embedding parameter in DSN+ if err := database.RunMigrationsWithOptions(migrateDSN, migrationOpts); err != nil {// Log warning but don't fail startup - migrations might be handled externallylogger.Warnf(context.Background(), "Database migration failed: %v", err)logger.Warnf(diff --git a/migrations/versioned/000000_init.down.sql b/migrations/versioned/000000_init.down.sqlindex 34a8bae58..47f28966f 100644--- a/migrations/versioned/000000_init.down.sql+++ b/migrations/versioned/000000_init.down.sql@@ -1,10 +1,3 @@--- Drop indexes for embeddings-DROP INDEX IF EXISTS embeddings_unique_source;-DROP INDEX IF EXISTS embeddings_search_idx;---- Drop embeddings table-DROP TABLE IF EXISTS embeddings;--- Drop indexes for chunksDROP INDEX IF EXISTS idx_chunks_tenant_kg;DROP INDEX IF EXISTS idx_chunks_parent_id;diff --git a/migrations/versioned/000000_init.up.sql b/migrations/versioned/000000_init.up.sqlindex 24f70e5b7..962b6ea3d 100644--- a/migrations/versioned/000000_init.up.sql+++ b/migrations/versioned/000000_init.up.sql@@ -5,9 +5,6 @@ DO $$ BEGIN RAISE NOTICE '[Migration 000000] Starting initial database setup...'-- Create extensionsDO $$ BEGIN RAISE NOTICE '[Migration 000000] Creating extensions...'; END $$;CREATE EXTENSION IF NOT EXISTS "uuid-ossp";-CREATE EXTENSION IF NOT EXISTS vector;-CREATE EXTENSION IF NOT EXISTS pg_trgm;-CREATE EXTENSION IF NOT EXISTS pg_search;-- Create tenant tableDO $$ BEGIN RAISE NOTICE '[Migration 000000] Creating table: tenants'; END $$;@@ -211,71 +208,4 @@ CREATE INDEX IF NOT EXISTS idx_chunks_tenant_kg ON chunks(tenant_id, knowledge_iCREATE INDEX IF NOT EXISTS idx_chunks_parent_id ON chunks(parent_chunk_id);CREATE INDEX IF NOT EXISTS idx_chunks_chunk_type ON chunks(chunk_type);--- Create embeddings table-DO $$ BEGIN RAISE NOTICE '[Migration 000000] Creating table: embeddings'; END $$;-CREATE TABLE IF NOT EXISTS embeddings (- id SERIAL PRIMARY KEY,- created_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP,- updated_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP,-- source_id VARCHAR(64) NOT NULL,- source_type INTEGER NOT NULL,- chunk_id VARCHAR(64),- knowledge_id VARCHAR(64),- knowledge_base_id VARCHAR(64),- content TEXT,- dimension INTEGER NOT NULL,- embedding halfvec-);--DO $$ BEGIN RAISE NOTICE '[Migration 000000] Creating indexes for embeddings (this may take a while)...'; END $$;-CREATE UNIQUE INDEX IF NOT EXISTS embeddings_unique_source ON embeddings(source_id, source_type);---- Create BM25 search index (check if exists first)-DO $$-BEGIN- IF NOT EXISTS (SELECT 1 FROM pg_indexes WHERE indexname = 'embeddings_search_idx') THEN- CREATE INDEX embeddings_search_idx ON embeddings- USING bm25 (id, knowledge_base_id, content, knowledge_id, chunk_id)- WITH (- key_field = 'id',- text_fields = '{- "content": {- "tokenizer": {"type": "chinese_lindera"}- }- }'- );- RAISE NOTICE '[Migration 000000] Created BM25 index embeddings_search_idx';- ELSE- RAISE NOTICE '[Migration 000000] BM25 index embeddings_search_idx already exists';- END IF;-END $$;---- Create HNSW indexes for vector search (check if exists first)-DO $$-BEGIN- IF NOT EXISTS (SELECT 1 FROM pg_indexes WHERE indexname = 'embeddings_embedding_idx' OR indexname LIKE 'embeddings_embedding%3584%') THEN- CREATE INDEX embeddings_embedding_idx_3584 ON embeddings- USING hnsw ((embedding::halfvec(3584)) halfvec_cosine_ops)- WITH (m = 16, ef_construction = 64)- WHERE (dimension = 3584);- RAISE NOTICE '[Migration 000000] Created HNSW index for dimension 3584';- ELSE- RAISE NOTICE '[Migration 000000] HNSW index for dimension 3584 already exists';- END IF;-END $$;--DO $$-BEGIN- IF NOT EXISTS (SELECT 1 FROM pg_indexes WHERE indexname = 'embeddings_embedding_idx_798' OR indexname LIKE 'embeddings_embedding%798%') THEN- CREATE INDEX embeddings_embedding_idx_798 ON embeddings- USING hnsw ((embedding::halfvec(798)) halfvec_cosine_ops)- WITH (m = 16, ef_construction = 64)- WHERE (dimension = 798);- RAISE NOTICE '[Migration 000000] Created HNSW index for dimension 798';- ELSE- RAISE NOTICE '[Migration 000000] HNSW index for dimension 798 already exists';- END IF;-END $$;--DO $$ BEGIN RAISE NOTICE '[Migration 000000] Initial database setup completed successfully!'; END $$;+DO $$ BEGIN RAISE NOTICE '[Migration 000000] Initial database setup completed successfully!'; END $$;\ No newline at end of filediff --git a/migrations/versioned/000001_agent.down.sql b/migrations/versioned/000001_agent.down.sqlindex 0e73e45f1..bb53134f7 100644--- a/migrations/versioned/000001_agent.down.sql+++ b/migrations/versioned/000001_agent.down.sql@@ -28,15 +28,6 @@ ALTER TABLE chunksALTER TABLE chunksDROP COLUMN IF EXISTS status;-DROP INDEX IF EXISTS idx_embeddings_knowledge_base_id;---- Drop index-DROP INDEX IF EXISTS idx_embeddings_is_enabled;---- Remove is_enabled column-ALTER TABLE embeddings- DROP COLUMN IF EXISTS is_enabled;--- Drop indexes and columns referencing tagsDROP INDEX IF EXISTS idx_chunks_tag;ALTER TABLE chunks DROP COLUMN IF EXISTS tag_id;diff --git a/migrations/versioned/000001_agent.up.sql b/migrations/versioned/000001_agent.up.sqlindex 46d7382d4..29e93f90c 100644--- a/migrations/versioned/000001_agent.up.sql+++ b/migrations/versioned/000001_agent.up.sql@@ -223,23 +223,7 @@ CREATE INDEX IF NOT EXISTS idx_chunks_content_hash ON chunks(content_hash);-- Section 8: Embeddings Enhancements-- ============================================================================-DO $$ BEGIN RAISE NOTICE '[Migration 000001] Adding embeddings enhancements...'; END $$;---- Add is_enabled column-ALTER TABLE embeddings ADD COLUMN IF NOT EXISTS is_enabled BOOLEAN DEFAULT TRUE;-CREATE INDEX IF NOT EXISTS idx_embeddings_is_enabled ON embeddings(is_enabled);---- Add index for knowledge_base_id-CREATE INDEX IF NOT EXISTS idx_embeddings_knowledge_base_id ON embeddings(knowledge_base_id);---- Reindex BM25 search index (idempotent - will rebuild if exists)-DO $$-BEGIN- IF EXISTS (SELECT 1 FROM pg_indexes WHERE indexname = 'embeddings_search_idx') THEN- REINDEX INDEX embeddings_search_idx;- RAISE NOTICE '[Migration 000001] Reindexed embeddings_search_idx';- END IF;-END $$;+-- move embeddings to 000002 migrations-- ============================================================================-- Section 9: Models Enhancementsdiff --git a/migrations/versioned/000002_embeddings.down.sql b/migrations/versioned/000002_embeddings.down.sqlnew file mode 100644index 000000000..e5b20e362--- /dev/null+++ b/migrations/versioned/000002_embeddings.down.sql@@ -0,0 +1,14 @@+-- Drop indexes for embeddings+DROP INDEX IF EXISTS idx_embeddings_knowledge_base_id;++-- Drop index+DROP INDEX IF EXISTS idx_embeddings_is_enabled;++DROP INDEX IF EXISTS embeddings_unique_source;+DROP INDEX IF EXISTS embeddings_search_idx;+DROP INDEX IF EXISTS embeddings_embedding_idx_3584;+DROP INDEX IF EXISTS embeddings_embedding_idx_798;+DROP INDEX IF EXISTS embeddings_embedding_idx;++-- Drop embeddings table+DROP TABLE IF EXISTS embeddings;diff --git a/migrations/versioned/000002_embeddings.up.sql b/migrations/versioned/000002_embeddings.up.sqlnew file mode 100644index 000000000..d2ee17f74--- /dev/null+++ b/migrations/versioned/000002_embeddings.up.sql@@ -0,0 +1,94 @@+-- Migration: embeddings (conditional)+-- Description: Create embeddings table and indexes (only for postgres retrieve driver)++DO $$+BEGIN+ -- Check if we should skip this migration+ IF current_setting('app.skip_embedding', true) = 'true' THEN+ RAISE NOTICE 'Skipping migration embeddings (app.skip_embedding=true)';+ RETURN;+ END IF;++ -- If we reach here, proceed with migration+ RAISE NOTICE '[Conditional Migration: embeddings] Creating embeddings table...';++ -- Create required extensions+ CREATE EXTENSION IF NOT EXISTS vector;+ CREATE EXTENSION IF NOT EXISTS pg_trgm;+ CREATE EXTENSION IF NOT EXISTS pg_search;++ -- Create embeddings table+ RAISE NOTICE '[Conditional Migration: embeddings] Creating indexes for embeddings (this may take a while)...';++ CREATE TABLE IF NOT EXISTS embeddings (+ id SERIAL PRIMARY KEY,+ created_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP,+ updated_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP,++ source_id VARCHAR(64) NOT NULL,+ source_type INTEGER NOT NULL,+ chunk_id VARCHAR(64),+ knowledge_id VARCHAR(64),+ knowledge_base_id VARCHAR(64),+ content TEXT,+ dimension INTEGER NOT NULL,+ embedding halfvec+ );++ CREATE UNIQUE INDEX IF NOT EXISTS embeddings_unique_source ON embeddings(source_id, source_type);++ -- Create BM25 search index (check if exists first)+ IF NOT EXISTS (SELECT 1 FROM pg_indexes WHERE indexname = 'embeddings_search_idx') THEN+ CREATE INDEX embeddings_search_idx ON embeddings+ USING bm25 (id, knowledge_base_id, content, knowledge_id, chunk_id)+ WITH (+ key_field = 'id',+ text_fields = '{+ "content": {+ "tokenizer": {"type": "chinese_lindera"}+ }+ }'+ );+ RAISE NOTICE '[Conditional Migration: embeddings] Created BM25 index embeddings_search_idx';+ ELSE+ RAISE NOTICE '[Conditional Migration: embeddings] BM25 index embeddings_search_idx already exists';+ END IF;++ -- Create HNSW indexes for vector search (check if exists first)+ IF NOT EXISTS (SELECT 1 FROM pg_indexes WHERE indexname = 'embeddings_embedding_idx' OR indexname LIKE 'embeddings_embedding%3584%') THEN+ CREATE INDEX embeddings_embedding_idx_3584 ON embeddings+ USING hnsw ((embedding::halfvec(3584)) halfvec_cosine_ops)+ WITH (m = 16, ef_construction = 64)+ WHERE (dimension = 3584);+ RAISE NOTICE '[Conditional Migration: embeddings] Created HNSW index for dimension 3584';+ ELSE+ RAISE NOTICE '[Conditional Migration: embeddings] HNSW index for dimension 3584 already exists';+ END IF;++ IF NOT EXISTS (SELECT 1 FROM pg_indexes WHERE indexname = 'embeddings_embedding_idx_798' OR indexname LIKE 'embeddings_embedding%798%') THEN+ CREATE INDEX embeddings_embedding_idx_798 ON embeddings+ USING hnsw ((embedding::halfvec(798)) halfvec_cosine_ops)+ WITH (m = 16, ef_construction = 64)+ WHERE (dimension = 798);+ RAISE NOTICE '[Conditional Migration: embeddings] Created HNSW index for dimension 798';+ ELSE+ RAISE NOTICE '[Conditional Migration: embeddings] HNSW index for dimension 798 already exists';+ END IF;++ RAISE NOTICE '[Migration 000002] Adding embeddings enhancements...';++ -- Add is_enabled column+ ALTER TABLE embeddings ADD COLUMN IF NOT EXISTS is_enabled BOOLEAN DEFAULT TRUE;+ CREATE INDEX IF NOT EXISTS idx_embeddings_is_enabled ON embeddings(is_enabled);++ -- Add index for knowledge_base_id+ CREATE INDEX IF NOT EXISTS idx_embeddings_knowledge_base_id ON embeddings(knowledge_base_id);++ -- Reindex BM25 search index (idempotent - will rebuild if exists)+ IF EXISTS (SELECT 1 FROM pg_indexes WHERE indexname = 'embeddings_search_idx') THEN+ REINDEX INDEX embeddings_search_idx;+ RAISE NOTICE '[Migration 000002] Reindexed embeddings_search_idx';+ END IF;++ RAISE NOTICE '[Conditional Migration: embeddings] Embeddings table setup completed successfully!';+END $$;