Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/redis-developer/redis-product-search
Visual and semantic vector similarity with Redis Stack, FastAPI, PyTorch and Huggingface.
https://github.com/redis-developer/redis-product-search
docker fastapi machine-learning react redis redis-stack redissearch single-page-application vector-database vector-search
Last synced: 1 day ago
JSON representation
Visual and semantic vector similarity with Redis Stack, FastAPI, PyTorch and Huggingface.
- Host: GitHub
- URL: https://github.com/redis-developer/redis-product-search
- Owner: redis-developer
- License: bsd-3-clause
- Created: 2022-06-13T06:56:49.000Z (over 2 years ago)
- Default Branch: master
- Last Pushed: 2024-08-01T16:55:09.000Z (5 months ago)
- Last Synced: 2024-12-16T10:19:25.335Z (9 days ago)
- Topics: docker, fastapi, machine-learning, react, redis, redis-stack, redissearch, single-page-application, vector-database, vector-search
- Language: Python
- Homepage: https://ecommerce.redisvl.com
- Size: 937 KB
- Stars: 157
- Watchers: 7
- Forks: 41
- Open Issues: 7
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
- redis-ai-resources - Product Search
- redis-ai-resources - Product Search
README
# Redis Vector Search Demo Application
This demo showcases the vector search similarity (VSS) capability within Redis Stack and Redis Enterprise.
Through the RediSearch module, vector types and indexes can be added to Redis. This turns Redis into
a highly performant vector database which can be used for all types of applications.The following Redis Stack capabilities are available in this demo:
- **Vector Similarity Search**
- by image
- by text
- **Multiple vector indexing types**
- HNSW
- Flat (brute-force)
- **Hybrid Queries**
- Apply tags as pre-filter for vector search## Application
This app was built as a Single Page Application (SPA) with the following components:
- **[Redis Stack](https://redis.io/docs/stack/)**: Vector database + JSON storage
- **[RedisVL](https://redisvl.com)** for Python vector db client
- **[FastAPI](https://fastapi.tiangolo.com/)** for backend API
- **[Pydantic](https://pydantic-docs.helpmanual.io/)** for schema and validation
- **[React](https://reactjs.org/)** (with Typescript)
- **[Docker Compose](https://docs.docker.com/compose/)** for development
- **[MaterialUI](https://material-ui.com/)** for some UI elements
- **[React-Bootstrap](https://react-bootstrap.github.io/)** for some UI elements
- **[Pytorch/Img2Vec](https://github.com/christiansafka/img2vec)** and **[Huggingface Sentence Transformers](https://huggingface.co/sentence-transformers)** for vector embedding creationSome inspiration was taken from this [Cookiecutter project](https://github.com/Buuntu/fastapi-react)
and turned into a SPA application instead of a separate front-end server approach.### General Project Structure
Much inspiration taken from [tiangelo/full-stack-fastapi-template](https://github.com/tiangolo/full-stack-fastapi-template)
```
/backend
/productsearch
/api
/routes
product.py # primary API logic lives here
/db
load.py # seeds Redis DB
redis_helpers.py # redis util
/schema
# pydantic models for serialization/validation from API
/tests
/utils
config.py
spa.py # logic for serving compiled react project
main.py # entrypoint
/frontend
/public
# index, manifest, logos, etc.
/src
/config
/styles
/views
# primary components live hereapi.ts # logic for connecting with BE
App.tsx # project entry
Routes.tsk # route definitions
...
/data
# folder mounted as volume in Docker
# load script auto populates initial data from S3```
### Datasets
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)## Running the App with docker-compose
Before running the app, install [Docker Desktop](https://www.docker.com/products/docker-desktop/).#### Using Redis Cloud (recommended)
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
```3. Run the App:
```bash
$ docker compose -f docker-cloud-redis.yml up
```> 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
```bash
$ docker compose -f docker-local-redis.yml up
```## Running without docker-compose
### Run frontend
1. Install NPM packages
```bash
$ cd frontend/
$ npm install
````
2. Use `npm` to serve the application from your machine
```bash
$ npm run start
```
3. Navigate to `http://localhost:3000` in a browser.All changes to your local code will be reflected in your display in semi realtime.
### Run backend
Pre-step: install [poetry](https://python-poetry.org/).1. `cd backend`
2. `poetry install` to get necessary python deps
3. `poetry run start` to launch uvicorn server with FastAPI app### vscode debugger
Included in the project is a `./vscode/launch.json` for local debugging purposes.
### Troubleshooting
Sometimes you need to clear out some Docker cached artifacts. Run `docker system prune`, restart Docker Desktop, and try again.Open an issue here on GitHub and we will try to be responsive to these. Additionally, please consider [contributing](CONTRIBUTING.md).