A modern fashion search application built with FastAPI and LanceDB, featuring semantic search capabilities for H&M fashion items.
- Semantic Search: Find fashion items using natural language queries
- Filtering: Filter by product groups and item types
- Real-time Results: Fast search results with pagination
- Modern UI: Clean, responsive interface with product details modal
- Vector Database: Powered by LanceDB for efficient similarity search
- Backend: FastAPI (Python)
- Vector Database: LanceDB
- Embeddings: Sentence Transformers (CLIP ViT-B-32)
- Frontend: HTML, CSS, JavaScript
- AI Models: Hugging Face Transformers
- Clone the repository:
git clone <repository-url>
cd lancedb-ecommerce
- Install dependencies:
pip install -r requirements.txt
- Create the data directory:
mkdir -p data
- Run the FastAPI server:
uvicorn app:app --reload --host 0.0.0.0 --port 8000
- Open your browser and navigate to
http://localhost:8000/static/index.html
The application will automatically create an empty table when it starts. To populate it with fashion data:
- Prepare your data in a format compatible with the schema:
import pandas as pd
import lancedb
from sentence_transformers import SentenceTransformer
# Connect to the database
db = lancedb.connect("./data")
table = db.open_table("h&m-mini")
# Load your fashion data
data = pd.read_csv("your_fashion_data.csv")
# Generate embeddings for text fields (e.g., product descriptions)
encoder = SentenceTransformer("clip-ViT-B-32")
data['vector'] = data['detail_desc'].apply(lambda x: encoder.encode(x).tolist())
# Insert data into the table
table.add(data)
- The expected schema includes:
image_url
: URL to product imageprod_name
: Product namedetail_desc
: Product descriptionproduct_type_name
: Type of productindex_group_name
: Product category groupprice
: Product pricearticle_id
: Unique article identifieravailable
: Availability statuscolor
: Product colorsize
: Product sizevector
: 512-dimensional embedding vector
GET /search
: Search for fashion items with optional filtersGET /groups
: Get available product groupsGET /static/index.html
: Main application interface
Edit the Config
class in app.py
to customize:
- Database path
- Table name
- Embedding model
- Product group ordering
This LanceDB version offers several advantages:
- Local Storage: No need for external database server
- Simplified Setup: Automatic table creation and management
- Better Performance: Optimized for local development and testing
- Easier Deployment: Single file database that can be easily shared
- Fork the repository
- Create a feature branch
- Make your changes
- Submit a pull request
This project is licensed under the MIT License.