Skip to content

Commit 173a077

Browse files
Feat/raae 9/repo upgrades (#23)
updates structure, use redisvl, use poetry, and update react --------- Co-authored-by: Tyler Hutcherson <[email protected]>
1 parent 50b8d5b commit 173a077

File tree

115 files changed

+27923
-16504
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

115 files changed

+27923
-16504
lines changed

.github/workflows/run_tests.yml

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
name: Test Suite
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- master
7+
8+
push:
9+
branches:
10+
- master
11+
12+
jobs:
13+
test:
14+
name: Python ${{ matrix.python-version }} - ${{ matrix.connection }} [redis-stack ${{matrix.redis-stack-version}}]
15+
runs-on: ubuntu-latest
16+
17+
strategy:
18+
fail-fast: false
19+
matrix:
20+
python-version: ["3.11"]
21+
redis-stack-version: ['latest']
22+
23+
services:
24+
redis:
25+
image: redis/redis-stack-server:${{matrix.redis-stack-version}}
26+
ports:
27+
- 6379:6379
28+
29+
steps:
30+
- uses: actions/checkout@v2
31+
- name: Set up Python ${{ matrix.python-version }}
32+
uses: actions/setup-python@v4
33+
with:
34+
python-version: ${{ matrix.python-version }}
35+
cache: 'pip'
36+
37+
- name: Install Poetry
38+
uses: snok/install-poetry@v1
39+
40+
- name: Install dependencies
41+
working-directory: ./backend
42+
run: |
43+
poetry install --all-extras
44+
45+
- name: Run tests
46+
working-directory: ./backend
47+
run: |
48+
poetry run test

.gitignore

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
*.egg-info
2-
build
32
__pycache__
43
node_modules
54
.DS_Store
65
images
76
.ipynb_checkpoints
87
product_metadata.json
9-
product_vectors.json
8+
product_vectors.json
9+
data/
10+
!backend/data
11+
.env

.vscode/launch.json

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
// Use IntelliSense to learn about possible attributes.
3+
// Hover to view descriptions of existing attributes.
4+
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5+
"version": "0.2.0",
6+
"configurations": [
7+
{
8+
"name": "Python Debugger: FastAPI",
9+
"type": "debugpy",
10+
"cwd": "${workspaceFolder}/backend/",
11+
"env": {
12+
"PYTHONPATH": "${cwd}",
13+
"REDIS_HOST": "localhost",
14+
},
15+
"request": "launch",
16+
"module": "uvicorn",
17+
"args": [
18+
"productsearch.main:app",
19+
"--port=8888",
20+
"--reload"
21+
],
22+
"jinja": true,
23+
}
24+
]
25+
}

.vscode/settings.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"python.testing.pytestArgs": [
3+
"backend"
4+
],
5+
"python.testing.unittestEnabled": false,
6+
"python.testing.pytestEnabled": true,
7+
"python.testing.cwd": "${workspaceFolder}/backend/",
8+
}

Dockerfile

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,46 @@
1-
FROM node:18.8-alpine AS ReactImage
1+
FROM node:22.0-alpine AS ReactImage
22

3-
WORKDIR /app/gui
3+
WORKDIR /app/frontend
44

5-
ENV NODE_PATH=/app/gui/node_modules
6-
ENV PATH=$PATH:/app/gui/node_modules/.bin
5+
ENV NODE_PATH=/app/frontend/node_modules
6+
ENV PATH=$PATH:/app/frontend/node_modules/.bin
77

8-
COPY ./gui/package.json ./
9-
RUN yarn install --no-optional
8+
COPY ./frontend/package.json ./
9+
RUN npm install
1010

11-
ADD ./gui ./
12-
RUN yarn build
11+
ADD ./frontend ./
12+
RUN npm run build
1313

14-
FROM python:3.8-slim-buster AS ApiImage
14+
FROM python:3.11-slim-buster AS ApiImage
1515

1616
ENV PYTHONUNBUFFERED 1
1717
ENV PYTHONDONTWRITEBYTECODE 1
1818

19-
RUN python3 -m pip install --upgrade pip setuptools wheel
20-
2119
WORKDIR /app/
22-
COPY ./data/ ./data
20+
VOLUME [ "/data" ]
21+
22+
RUN apt-get update && \
23+
apt-get install -y curl && \
24+
rm -rf /var/lib/apt/lists/*
25+
26+
RUN curl -sSL https://install.python-poetry.org | POETRY_HOME=/opt/poetry python && \
27+
cd /usr/local/bin && \
28+
ln -s /opt/poetry/bin/poetry && \
29+
poetry config virtualenvs.create false
2330

2431
RUN mkdir -p /app/backend
32+
33+
# copy deps first so we don't have to reload everytime
34+
COPY ./backend/poetry.lock ./backend/pyproject.toml ./backend/
35+
2536
WORKDIR /app/backend
37+
RUN poetry install --all-extras --no-interaction
2638

27-
COPY ./app/ .
28-
RUN pip install -e .
39+
COPY ./backend/ .
2940

3041
# add static react files to fastapi image
31-
COPY --from=ReactImage /app/gui/build /app/backend/vecsim_app/templates/build
42+
COPY --from=ReactImage /app/frontend/build /app/backend/productsearch/templates/build
3243

3344
LABEL org.opencontainers.image.source https://github.com/RedisVentures/redis-product-search
3445

35-
WORKDIR /app/backend/vecsim_app
36-
37-
CMD ["sh", "./entrypoint.sh"]
46+
CMD ["poetry", "run", "start-app"]

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
BSD 3-Clause License
22

3-
Copyright (c) 2022, Sam Partee
3+
Copyright (c) 2022, Redis Inc
44
All rights reserved.
55

66
Redistribution and use in source and binary forms, with or without

README.md

Lines changed: 65 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11

22
<div align="center">
3-
<a href="https://github.com/spartee/redis-vector-search"><img src="https://github.com/Spartee/redis-vector-search/blob/master/app/vecsim_app/data/redis-logo.png?raw=true" width="30%"><img></a>
3+
<a href="https://github.com/spartee/redis-vector-search"><img src="https://redis.io/wp-content/uploads/2024/04/Logotype.svg?raw=true" width="30%"><img></a>
44
<br />
55
<br />
66
<div display="inline-block">
77
<a href="https://ecommerce.redisventures.com"><b>Hosted Demo</b></a>&nbsp;&nbsp;&nbsp;
8-
<a href="https://github.com/Spartee/redis-vector-search"><b>Code</b></a>&nbsp;&nbsp;&nbsp;
8+
<a href="https://github.com/redis-developer/redis-product-search"><b>Code</b></a>&nbsp;&nbsp;&nbsp;
99
<a href="https://redis.io/docs/stack/search/reference/vectors/"><b>Redis VSS Documentation</b></a>&nbsp;&nbsp;&nbsp;
1010
</div>
1111
<br />
@@ -33,23 +33,57 @@ The following Redis Stack capabilities are available in this demo:
3333
This app was built as a Single Page Application (SPA) with the following components:
3434

3535
- **[Redis Stack](https://redis.io/docs/stack/)**: Vector database + JSON storage
36-
- **[FastAPI](https://fastapi.tiangolo.com/)** (Python 3.8)
37-
- JWT authentication using [OAuth2 "password
38-
flow"](https://fastapi.tiangolo.com/tutorial/security/simple-oauth2/) and
39-
PyJWT
36+
- **[RedisVL](https://redisvl.com)** for Python vector db client
37+
- **[FastAPI](https://fastapi.tiangolo.com/)** for backend API
4038
- **[Pydantic](https://pydantic-docs.helpmanual.io/)** for schema and validation
4139
- **[React](https://reactjs.org/)** (with Typescript)
42-
- **[Redis OM](https://redis.io/docs/stack/get-started/tutorials/stack-python/)** for ORM
4340
- **[Docker Compose](https://docs.docker.com/compose/)** for development
4441
- **[MaterialUI](https://material-ui.com/)** for some UI elements
4542
- **[React-Bootstrap](https://react-bootstrap.github.io/)** for some UI elements
46-
- **[react-admin](https://github.com/marmelab/react-admin)** for the admin dashboard
47-
- Using the same token based authentication as FastAPI backend (JWT)
4843
- **[Pytorch/Img2Vec](https://github.com/christiansafka/img2vec)** and **[Huggingface Sentence Transformers](https://huggingface.co/sentence-transformers)** for vector embedding creation
4944

5045
Some inspiration was taken from this [Cookiecutter project](https://github.com/Buuntu/fastapi-react)
5146
and turned into a SPA application instead of a separate front-end server approach.
5247

48+
### General Project Structure
49+
50+
Much inspiration taken from [tiangelo/full-stack-fastapi-template](https://github.com/tiangolo/full-stack-fastapi-template)
51+
52+
```
53+
/backend
54+
/productsearch
55+
/api
56+
/routes
57+
product.py # primary API logic lives here
58+
/db
59+
load.py # seeds Redis DB
60+
redis_helpers.py # redis util
61+
/schema
62+
# pydantic models for serialization/validation from API
63+
/tests
64+
/utils
65+
config.py
66+
spa.py # logic for serving compiled react project
67+
main.py # entrypoint
68+
/frontend
69+
/public
70+
# index, manifest, logos, etc.
71+
/src
72+
/config
73+
/styles
74+
/views
75+
# primary components live here
76+
77+
api.ts # logic for connecting with BE
78+
App.tsx # project entry
79+
Routes.tsk # route definitions
80+
...
81+
/data
82+
# folder mounted as volume in Docker
83+
# load script auto populates initial data from S3
84+
85+
```
86+
5387
### Datasets
5488

5589
The dataset was taken from the the following Kaggle links.
@@ -58,12 +92,10 @@ The dataset was taken from the the following Kaggle links.
5892
- [Smaller Dataset](https://www.kaggle.com/datasets/paramaggarwal/fashion-product-images-small)
5993

6094

61-
## Running the App
95+
## Running the App with docker-compose
6296
Before running the app, install [Docker Desktop](https://www.docker.com/products/docker-desktop/).
6397

64-
65-
66-
#### Redis Cloud (recommended)
98+
#### Using Redis Cloud (recommended)
6799

68100
1. [Get your Redis Cloud Database](https://app.redislabs.com/) (if needed).
69101

@@ -81,34 +113,39 @@ Before running the app, install [Docker Desktop](https://www.docker.com/products
81113

82114
> 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.
83115

84-
#### Redis Docker
116+
#### Using Redis Docker
85117
```bash
86118
$ docker compose -f docker-local-redis.yml up
87119
```
88120

89-
### Customizing (optional)
90-
You can use the Jupyter Notebook in the `data/` directory to create product embeddings and product metadata JSON files. Both files will end up stored in the `data/` directory and used when creating your own container.
91-
92-
Create your own containers using the `build.sh` script and then make sure to update the `.yml` file with the right image name.
121+
## Running without docker-compose
93122

123+
### Run frontend
94124

95-
### Using a React development env
96-
It's typically easier to write front end code in an interactive environment, testing changes in realtime.
97-
98-
1. Deploy the app using steps above.
99-
2. Install NPM packages (you may need to use `npm` to install `yarn`)
125+
1. Install NPM packages
100126
```bash
101-
$ cd gui/
102-
$ yarn install --no-optional
127+
$ cd frontend/
128+
$ npm install
103129
````
104-
4. Use `yarn` to serve the application from your machine
130+
2. Use `npm` to serve the application from your machine
105131
```bash
106-
$ yarn start
132+
$ npm run start
107133
```
108-
5. Navigate to `http://localhost:3000` in a browser.
134+
3. Navigate to `http://localhost:3000` in a browser.
109135

110136
All changes to your local code will be reflected in your display in semi realtime.
111137

138+
### Run backend
139+
Pre-step: install [poetry](https://python-poetry.org/).
140+
141+
1. `cd backend`
142+
2. `poetry install` to get necessary python deps
143+
3. `poetry run start` to launch uvicorn server with FastAPI app
144+
145+
### vscode debugger
146+
147+
Included in the project is a `./vscode/launch.json` for local debugging purposes.
148+
112149
### Troubleshooting
113150
Sometimes you need to clear out some Docker cached artifacts. Run `docker system prune`, restart Docker Desktop, and try again.
114151

app/requirements.txt

Lines changed: 0 additions & 7 deletions
This file was deleted.

app/setup.cfg

Lines changed: 0 additions & 43 deletions
This file was deleted.

app/setup.py

Lines changed: 0 additions & 4 deletions
This file was deleted.

0 commit comments

Comments
 (0)