Spaces:
Runtime error
Runtime error
update with pgvector setup and tested docker
Browse files- .env +0 -5
- Dockerfile +0 -6
- database.py +3 -2
- docker-compose.yml +30 -0
.env
DELETED
|
@@ -1,5 +0,0 @@
|
|
| 1 |
-
OPENAI_API_KEY = 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
|
| 2 |
-
PG_VECTOR_HOST = db # Use the service name 'db' instead of localhost
|
| 3 |
-
PG_VECTOR_USER = myuser
|
| 4 |
-
PG_VECTOR_PASSWORD = mypassword
|
| 5 |
-
PGDATABASE = mydb
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Dockerfile
CHANGED
|
@@ -22,12 +22,6 @@ RUN pip install --no-cache-dir -r requirements.txt
|
|
| 22 |
# Expose the port Streamlit runs on
|
| 23 |
EXPOSE 8501
|
| 24 |
|
| 25 |
-
# # Set the default command to run the app
|
| 26 |
-
# CMD ["streamlit", "run", "app.py", "--server.port=8501", "--server.address=0.0.0.0"]
|
| 27 |
-
# Set the default command to run the app
|
| 28 |
-
# CMD ["streamlit", "run", "app.py", "--server.port=${PORT:-8501}", "--server.address=0.0.0.0", "--server.enableCORS=false", "--server.enableXsrfProtection=false"]
|
| 29 |
-
|
| 30 |
-
# ENTRYPOINT ["streamlit", "run", "app.py", "--server.port=8501", "--server.address=0.0.0.0"]
|
| 31 |
|
| 32 |
ENTRYPOINT ["bash", "-c", "streamlit run app.py --server.port=${PORT:-8501} --server.address=0.0.0.0"]
|
| 33 |
|
|
|
|
| 22 |
# Expose the port Streamlit runs on
|
| 23 |
EXPOSE 8501
|
| 24 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
|
| 26 |
ENTRYPOINT ["bash", "-c", "streamlit run app.py --server.port=${PORT:-8501} --server.address=0.0.0.0"]
|
| 27 |
|
database.py
CHANGED
|
@@ -6,5 +6,6 @@ host = os.getenv("PG_VECTOR_HOST")
|
|
| 6 |
user = os.getenv("PG_VECTOR_USER")
|
| 7 |
password = os.getenv("PG_VECTOR_PASSWORD")
|
| 8 |
COLLECTION_NAME = os.getenv("PGDATABASE")
|
| 9 |
-
CONNECTION_STRING = "postgresql+psycopg://
|
| 10 |
-
|
|
|
|
|
|
| 6 |
user = os.getenv("PG_VECTOR_USER")
|
| 7 |
password = os.getenv("PG_VECTOR_PASSWORD")
|
| 8 |
COLLECTION_NAME = os.getenv("PGDATABASE")
|
| 9 |
+
CONNECTION_STRING = f"postgresql+psycopg://{user}:{password}@{host}:5432/{COLLECTION_NAME}"
|
| 10 |
+
|
| 11 |
+
|
docker-compose.yml
CHANGED
|
@@ -9,11 +9,14 @@ services:
|
|
| 9 |
depends_on:
|
| 10 |
redis-stack:
|
| 11 |
condition: service_healthy # Wait for Redis to be ready
|
|
|
|
|
|
|
| 12 |
env_file:
|
| 13 |
- .env # Load environment variables from .env file
|
| 14 |
environment:
|
| 15 |
- REDIS_HOST=redis-stack
|
| 16 |
- REDIS_PORT=6379
|
|
|
|
| 17 |
networks:
|
| 18 |
- app_network
|
| 19 |
|
|
@@ -29,6 +32,33 @@ services:
|
|
| 29 |
timeout: 3s
|
| 30 |
retries: 5
|
| 31 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
networks:
|
| 33 |
app_network:
|
| 34 |
driver: bridge
|
|
|
|
| 9 |
depends_on:
|
| 10 |
redis-stack:
|
| 11 |
condition: service_healthy # Wait for Redis to be ready
|
| 12 |
+
db:
|
| 13 |
+
condition: service_healthy # Wait for PostgreSQL to be ready
|
| 14 |
env_file:
|
| 15 |
- .env # Load environment variables from .env file
|
| 16 |
environment:
|
| 17 |
- REDIS_HOST=redis-stack
|
| 18 |
- REDIS_PORT=6379
|
| 19 |
+
- DATABASE_URL=postgresql+psycopg://${PG_VECTOR_USER}:${PG_VECTOR_PASSWORD}@${PG_VECTOR_HOST}:5432/${PGDATABASE}
|
| 20 |
networks:
|
| 21 |
- app_network
|
| 22 |
|
|
|
|
| 32 |
timeout: 3s
|
| 33 |
retries: 5
|
| 34 |
|
| 35 |
+
db:
|
| 36 |
+
image: pgvector/pgvector:pg16 # Use PostgreSQL with pgvector
|
| 37 |
+
container_name: pgvector_db
|
| 38 |
+
restart: always
|
| 39 |
+
env_file:
|
| 40 |
+
- .env # Load credentials from .env file
|
| 41 |
+
environment:
|
| 42 |
+
POSTGRES_USER: ${PG_VECTOR_USER}
|
| 43 |
+
POSTGRES_PASSWORD: ${PG_VECTOR_PASSWORD}
|
| 44 |
+
POSTGRES_DB: ${PGDATABASE}
|
| 45 |
+
ports:
|
| 46 |
+
- "6024:5432"
|
| 47 |
+
volumes:
|
| 48 |
+
- pgvector_data:/var/lib/postgresql/data # Persist database
|
| 49 |
+
- ./init-scripts:/docker-entrypoint-initdb.d # Auto-run SQL scripts
|
| 50 |
+
networks:
|
| 51 |
+
- app_network
|
| 52 |
+
healthcheck:
|
| 53 |
+
test: ["CMD-SHELL", "pg_isready -U ${PG_VECTOR_USER} -d ${PGDATABASE}"]
|
| 54 |
+
interval: 10s
|
| 55 |
+
timeout: 5s
|
| 56 |
+
retries: 5
|
| 57 |
+
|
| 58 |
+
volumes:
|
| 59 |
+
pgvector_data:
|
| 60 |
+
driver: local
|
| 61 |
+
|
| 62 |
networks:
|
| 63 |
app_network:
|
| 64 |
driver: bridge
|