Awesome
<div align="center"> <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> <br /> <br /> <div display="inline-block"> <a href="https://ecommerce.redisventures.com"><b>Hosted Demo</b></a> <a href="https://github.com/redis-developer/redis-product-search"><b>Code</b></a> <a href="https://redis.io/docs/stack/search/reference/vectors/"><b>Redis VSS Documentation</b></a> </div> <br /> <br /> </div>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: Vector database + JSON storage
- RedisVL for Python vector db client
- FastAPI for backend API
- Pydantic for schema and validation
- React (with Typescript)
- Docker Compose for development
- MaterialUI for some UI elements
- React-Bootstrap for some UI elements
- Pytorch/Img2Vec and Huggingface Sentence Transformers for vector embedding creation
Some inspiration was taken from this Cookiecutter project 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
/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 here
api.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.
Running the App with docker-compose
Before running the app, install Docker Desktop.
Using Redis Cloud (recommended)
-
Get your Redis Cloud Database (if needed).
-
Export Redis Endpoint Environment Variables:
$ export REDIS_HOST=your-redis-host $ export REDIS_PORT=your-redis-port $ export REDIS_PASSOWRD=your-redis-password
-
Run the App:
$ 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
$ docker compose -f docker-local-redis.yml up
Running without docker-compose
Run frontend
- Install NPM packages
$ cd frontend/ $ npm install
- Use
npm
to serve the application from your machine$ npm run start
- 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.
cd backend
poetry install
to get necessary python depspoetry 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.