A .NET web application that integrates with RavenDB and OpenAI's CLIP model for category management with image embeddings.
- Category Management: Create, view, and search categories
- Image Support: Upload and display images for categories stored as RavenDB attachments
- Text Search: Traditional text-based search through category names and descriptions
- Semantic Search: AI-powered search using OpenAI embeddings
- Embedding Generation: Generate embeddings for categories using OpenAI's CLIP model
- Modern UI: Bootstrap-based responsive interface
- RavenDB: Install and run RavenDB locally on port 8080
- OpenAI API Key: Get an API key from OpenAI
- .NET 8 SDK: Install .NET 8 SDK
- Download RavenDB from https://ravendb.net/download
- Run RavenDB locally (default port 8080)
- The application will automatically create the database "CategoryImageDB"
- Get your OpenAI API key from https://platform.openai.com/api-keys
- Update the API key in
appsettings.jsonorappsettings.Development.json:
{
"OpenAI": {
"ApiKey": "your-actual-openai-api-key-here"
}
}# Restore packages
dotnet restore
# Run the application
dotnet runThe application will be available at https://localhost:5001 or http://localhost:5000.
- Create Sample Data: Click "Create Sample Data" to generate some example categories
- Initialize System: Click "Initialize System" to generate embeddings for all categories using OpenAI's CLIP model
- Browse Categories: View all categories with their images
- Text Search: Use the search bar for traditional keyword search
- Semantic Search: Check "Use AI Semantic Search" for AI-powered search
- Add Categories: Click "Add Category" to create new categories with optional images
- Category: Main entity with name, description, image support, and embeddings
- SearchRequest: DTO for search operations
- CategoryService: Handles CRUD operations and similarity search
- OpenAIService: Integrates with OpenAI API for embeddings
- EmbeddingService: Orchestrates embedding generation
- RavenDB: Document database with attachment support
- Indexes: Custom indexes for text search and embedding operations
GET /- Main categories page with searchGET /Home/CreateCategory- Category creation formPOST /Home/CreateCategory- Create new categoryPOST /Home/InitializeSystem- Generate embeddings for all categoriesPOST /Home/CreateSampleData- Create sample categoriesGET /Home/GetCategoryImage/{id}- Retrieve category image
- For categories with images: Generate embeddings from the image using OpenAI's CLIP model
- For categories without images: Generate embeddings from text (name + description)
- Store embeddings in RavenDB for similarity search
- Text Search: Uses RavenDB's full-text search capabilities
- Semantic Search: Uses cosine similarity with OpenAI embeddings
- Images are stored as RavenDB attachments
- Supports various image formats (JPEG, PNG, etc.)
- Images are displayed directly from RavenDB
Key configuration options in appsettings.json:
{
"OpenAI": {
"ApiKey": "your-openai-api-key"
},
"RavenDB": {
"Urls": ["http://localhost:8080"],
"Database": "CategoryImageDB"
}
}- RavenDB.Client: Document database client
- Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation: For development-time view compilation
- Newtonsoft.Json: JSON serialization
- Bootstrap 5: UI framework
- Font Awesome: Icons
- The application uses OpenAI's
text-embedding-3-largemodel - Rate limiting is implemented to avoid OpenAI API limits
- Embeddings are cached in RavenDB to avoid regeneration
- The UI is responsive and works on mobile devices