-
Notifications
You must be signed in to change notification settings - Fork 4
Add pgvector as default KB store #152
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| FROM pgvector/pgvector:pg17 | ||
|
|
||
| COPY init-dbs.sh /docker-entrypoint-initdb.d/init-dbs.sh | ||
| RUN chmod +x /docker-entrypoint-initdb.d/init-dbs.sh | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,18 +1,37 @@ | ||
| services: | ||
| mindsdb: | ||
| image: mindsdb/mindsdb:v25.12.0 | ||
| depends_on: | ||
| pgvector: | ||
| condition: service_healthy | ||
| ports: | ||
| - "47334:47334" | ||
| - "47335:47335" | ||
| - "47336:47336" | ||
| - "47337:47337" | ||
| - "47338:47338" | ||
| volumes: | ||
| - data:/opt/mindsdb/data | ||
| - config:/opt/mindsdb/config | ||
| container_name: mindsdb_service | ||
| pull_policy: always | ||
| environment: | ||
| MINDSDB_DB_CON: "postgresql://mindsdb:mindsdb@pgvector/mindsdb" | ||
| KB_PGVECTOR_URL: "postgresql://mindsdb:mindsdb@pgvector/kb" | ||
|
|
||
| pgvector: | ||
| image: mindsdb/mindsdb-docker-extension-pgvector:latest | ||
| container_name: pgvector_service | ||
| volumes: | ||
| - data_pg:/var/lib/postgresql/data | ||
| environment: | ||
| POSTGRES_USER: "postgres" | ||
| POSTGRES_PASSWORD: "postgres" | ||
| POSTGRES_DB: "postgres" | ||
| healthcheck: | ||
| test: ["CMD-SHELL", "pg_isready -U postgres"] | ||
| interval: 5s | ||
| timeout: 5s | ||
| retries: 10 | ||
|
|
||
| volumes: | ||
| data: | ||
| config: | ||
| data_pg: |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| #!/bin/bash | ||
| set -e | ||
|
|
||
| echo "Initializing databases..." | ||
|
|
||
| # Check required environment variables | ||
| if [[ -z "${POSTGRES_USER:-}" || -z "${POSTGRES_DB:-}" ]]; then | ||
| echo "Error: POSTGRES_USER and POSTGRES_DB environment variables must be set." >&2 | ||
| exit 1 | ||
| fi | ||
|
|
||
| # Log message for clarity | ||
| echo "Creating additional databases..." | ||
|
|
||
| # Function to create a database | ||
| create_database() { | ||
| local db_name=$1 | ||
| echo "Creating database: $db_name" | ||
| psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" <<-EOSQL | ||
| SELECT 'CREATE DATABASE $db_name' | ||
| WHERE NOT EXISTS (SELECT FROM pg_database WHERE datname = '$db_name')\gexec | ||
| EOSQL | ||
| psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" <<-EOSQL | ||
| SELECT 'CREATE DATABASE kb' | ||
| WHERE NOT EXISTS (SELECT FROM pg_database WHERE datname = 'kb')\gexec | ||
| EOSQL | ||
| } | ||
|
|
||
| # Function to create a user with permissions | ||
| create_user() { | ||
| local username=$1 | ||
| local userpassword=$2 | ||
| local db_name=$3 | ||
| echo "Creating user: $username with access to database: $db_name" | ||
| psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" --dbname "$db_name" <<-EOSQL | ||
| DO \$\$ | ||
| BEGIN | ||
| IF NOT EXISTS (SELECT FROM pg_roles WHERE rolname = '$username') THEN | ||
| CREATE USER $username WITH PASSWORD '$userpassword'; | ||
| ELSE | ||
| RAISE NOTICE 'User $username already exists. Skipping.'; | ||
| END IF; | ||
| END | ||
| \$\$; | ||
| GRANT ALL PRIVILEGES ON DATABASE $db_name TO $username; | ||
| GRANT ALL PRIVILEGES ON SCHEMA public TO $username; | ||
| GRANT ALL ON SCHEMA public TO $username; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this is handled by |
||
| EOSQL | ||
|
|
||
| # Do the same for the kb db | ||
| psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" --dbname "kb" <<-EOSQL | ||
| DO \$\$ | ||
| BEGIN | ||
| IF NOT EXISTS (SELECT FROM pg_roles WHERE rolname = '$username') THEN | ||
| CREATE USER $username WITH PASSWORD '$userpassword'; | ||
| ELSE | ||
| RAISE NOTICE 'User $username already exists. Skipping.'; | ||
| END IF; | ||
| END | ||
| \$\$; | ||
| GRANT ALL PRIVILEGES ON DATABASE kb TO $username; | ||
| GRANT ALL PRIVILEGES ON SCHEMA public TO $username; | ||
| GRANT ALL ON SCHEMA public TO $username; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here handled by GRANT ALL PRIVILEGES ON SCHEMA public TO $username;
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are you saying we can get rid of? |
||
| CREATE EXTENSION IF NOT EXISTS vector; | ||
| EOSQL | ||
| } | ||
|
|
||
| # Create databases | ||
| create_database "mindsdb" | ||
|
|
||
| # Create user with permissions in a database | ||
| create_user "mindsdb" "mindsdb" "mindsdb" | ||
|
|
||
| echo "Database and user creation completed successfully." | ||
Uh oh!
There was an error while loading. Please reload this page.