From 4631209fbc35384ce4677a8ed73239ede8f96a0f Mon Sep 17 00:00:00 2001 From: Robert Shelton Date: Fri, 31 Jan 2025 10:38:25 -0500 Subject: [PATCH 1/5] fix local docker --- README.md | 30 ++++++++++++++++++++++-------- backend/productsearch/config.py | 1 + backend/productsearch/db/load.py | 5 ++--- docker-local-redis.yml | 8 ++------ 4 files changed, 27 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index c9be77e..b4c42e4 100644 --- a/README.md +++ b/README.md @@ -91,20 +91,23 @@ The dataset was taken from the the following Kaggle links. - [Large Dataset](https://www.kaggle.com/datasets/paramaggarwal/fashion-product-images-dataset) - [Smaller Dataset](https://www.kaggle.com/datasets/paramaggarwal/fashion-product-images-small) +A formatted version is available for use with this demo at: + ## Running the App with docker-compose Before running the app, install [Docker Desktop](https://www.docker.com/products/docker-desktop/). -#### Using Redis Cloud (recommended) +#### Using Redis Cloud 1. [Get your Redis Cloud Database](https://app.redislabs.com/) (if needed). -2. Export Redis Endpoint Environment Variables: - ```bash - $ export REDIS_HOST=your-redis-host - $ export REDIS_PORT=your-redis-port - $ export REDIS_PASSOWRD=your-redis-password - ``` +2. `touch .env` and update with cloud values + +```bash +REDIS_HOST=your-redis-host +REDIS_PORT=your-redis-port +REDIS_PASSOWRD=your-redis-password +``` 3. Run the App: ```bash @@ -113,11 +116,22 @@ Before running the app, install [Docker Desktop](https://www.docker.com/products > The benefit of this approach is that the db will persist beyond application runs. So you can make updates and re run the app without having to provision the dataset or create another search index. -#### Using Redis Docker +#### Running the app locally using docker + +1. `touch .env` and update with local values + +```bash +REDIS_HOST=redis +REDIS_PORT=6379 +``` + +2. Run compose command ```bash $ docker compose -f docker-local-redis.yml up ``` +Note: you can add `--build` and `--force-recreate` if caching old images. + ## Running without docker-compose ### Run frontend diff --git a/backend/productsearch/config.py b/backend/productsearch/config.py index cc94b9b..0b0546b 100644 --- a/backend/productsearch/config.py +++ b/backend/productsearch/config.py @@ -16,6 +16,7 @@ API_DOCS = "/api/docs" OPENAPI_DOCS = "/api/openapi.json" INDEX_NAME = "products" + REDIS_HOST = os.environ.get("REDIS_HOST", "redis-vector-db") REDIS_PORT = os.environ.get("REDIS_PORT", 6379) REDIS_DB = os.environ.get("REDIS_DB", 0) diff --git a/backend/productsearch/db/load.py b/backend/productsearch/db/load.py index 983191e..c58fbed 100644 --- a/backend/productsearch/db/load.py +++ b/backend/productsearch/db/load.py @@ -1,14 +1,13 @@ #!/usr/bin/env python3 import asyncio import json -import requests import os from typing import List import numpy as np -from redisvl.index import AsyncSearchIndex - +import requests from productsearch import config +from redisvl.index import AsyncSearchIndex def read_from_s3(): diff --git a/docker-local-redis.yml b/docker-local-redis.yml index f0ebad6..bb790c5 100644 --- a/docker-local-redis.yml +++ b/docker-local-redis.yml @@ -19,14 +19,10 @@ services: - "6379:6379" - "8001:8001" volumes: - - redis-vector-db:/data + - ./data:/app/data healthcheck: test: ["CMD", "redis-cli", "-h", "localhost", "-p", "6379", "ping"] interval: 2s timeout: 1m30s retries: 5 - start_period: 5s - - -volumes: - redis-vector-db: \ No newline at end of file + start_period: 5s \ No newline at end of file From 3054dfa327ef76d0a525707d2f871737b65dbf75 Mon Sep 17 00:00:00 2001 From: Robert Shelton Date: Fri, 31 Jan 2025 10:59:58 -0500 Subject: [PATCH 2/5] keep redis volume --- docker-local-redis.yml | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/docker-local-redis.yml b/docker-local-redis.yml index bb790c5..f0ebad6 100644 --- a/docker-local-redis.yml +++ b/docker-local-redis.yml @@ -19,10 +19,14 @@ services: - "6379:6379" - "8001:8001" volumes: - - ./data:/app/data + - redis-vector-db:/data healthcheck: test: ["CMD", "redis-cli", "-h", "localhost", "-p", "6379", "ping"] interval: 2s timeout: 1m30s retries: 5 - start_period: 5s \ No newline at end of file + start_period: 5s + + +volumes: + redis-vector-db: \ No newline at end of file From 87b4e852740000bbc452d8ac534bf63f65fd0132 Mon Sep 17 00:00:00 2001 From: Robert Shelton Date: Fri, 31 Jan 2025 11:12:44 -0500 Subject: [PATCH 3/5] add back redis volume --- README.md | 9 ++------- template.env | 2 ++ 2 files changed, 4 insertions(+), 7 deletions(-) create mode 100644 template.env diff --git a/README.md b/README.md index b4c42e4..182850e 100644 --- a/README.md +++ b/README.md @@ -101,7 +101,7 @@ Before running the app, install [Docker Desktop](https://www.docker.com/products 1. [Get your Redis Cloud Database](https://app.redislabs.com/) (if needed). -2. `touch .env` and update with cloud values +2. `cp template.env .env` and update with cloud values ```bash REDIS_HOST=your-redis-host @@ -118,12 +118,7 @@ REDIS_PASSOWRD=your-redis-password #### Running the app locally using docker -1. `touch .env` and update with local values - -```bash -REDIS_HOST=redis -REDIS_PORT=6379 -``` +1. `cp template.env .env` 2. Run compose command ```bash diff --git a/template.env b/template.env new file mode 100644 index 0000000..23c3207 --- /dev/null +++ b/template.env @@ -0,0 +1,2 @@ +REDIS_HOST=redis +REDIS_PORT=6379 \ No newline at end of file From 2ae019187959fdd472542f7875b7e752f1f9da66 Mon Sep 17 00:00:00 2001 From: Robert Shelton Date: Fri, 31 Jan 2025 12:00:51 -0500 Subject: [PATCH 4/5] tweaks for better experience --- docker-local-redis.yml | 2 +- template.env | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docker-local-redis.yml b/docker-local-redis.yml index f0ebad6..e1d91d4 100644 --- a/docker-local-redis.yml +++ b/docker-local-redis.yml @@ -13,7 +13,7 @@ services: - "8888:8888" depends_on: - "redis" - redis: + redis-vector-db: image: redis/redis-stack:latest ports: - "6379:6379" diff --git a/template.env b/template.env index 23c3207..83049b9 100644 --- a/template.env +++ b/template.env @@ -1,2 +1,2 @@ -REDIS_HOST=redis +REDIS_HOST=redis-vector-db REDIS_PORT=6379 \ No newline at end of file From 9ba5ff9765da2497d7bbd8c1c18b37beac5c1f56 Mon Sep 17 00:00:00 2001 From: Robert Shelton Date: Fri, 31 Jan 2025 12:05:01 -0500 Subject: [PATCH 5/5] mend --- docker-local-redis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker-local-redis.yml b/docker-local-redis.yml index e1d91d4..ff8d1ca 100644 --- a/docker-local-redis.yml +++ b/docker-local-redis.yml @@ -12,7 +12,7 @@ services: ports: - "8888:8888" depends_on: - - "redis" + - "redis-vector-db" redis-vector-db: image: redis/redis-stack:latest ports: