Spaces:
Sleeping
Sleeping
File size: 26,882 Bytes
4e4132f | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 | <!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Image Search API Documentation</title>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
line-height: 1.6;
color: #333;
background: #fff;
}
.container {
max-width: 1200px;
margin: 0 auto;
padding: 0 20px;
}
header {
background: #000;
color: #fff;
padding: 2rem 0;
border-bottom: 3px solid #333;
}
header h1 {
font-size: 2.5rem;
font-weight: 300;
margin-bottom: 0.5rem;
}
header p {
font-size: 1.1rem;
opacity: 0.8;
}
nav {
background: #f8f9fa;
border-bottom: 1px solid #ddd;
padding: 1rem 0;
position: sticky;
top: 0;
z-index: 100;
}
nav ul {
list-style: none;
display: flex;
gap: 2rem;
}
nav a {
text-decoration: none;
color: #333;
font-weight: 500;
padding: 0.5rem 1rem;
border-radius: 4px;
transition: all 0.2s;
}
nav a:hover {
background: #000;
color: #fff;
}
main {
padding: 3rem 0;
}
.section {
margin-bottom: 4rem;
}
.section h2 {
font-size: 2rem;
margin-bottom: 1.5rem;
padding-bottom: 0.5rem;
border-bottom: 2px solid #000;
color: #000;
}
.section h3 {
font-size: 1.5rem;
margin: 2rem 0 1rem 0;
color: #333;
}
.section h4 {
font-size: 1.2rem;
margin: 1.5rem 0 0.5rem 0;
color: #555;
}
.code-block {
background: #f8f9fa;
border: 1px solid #ddd;
border-radius: 4px;
padding: 1.5rem;
margin: 1rem 0;
font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
font-size: 0.9rem;
overflow-x: auto;
}
.code-inline {
background: #f8f9fa;
padding: 0.2rem 0.4rem;
border-radius: 3px;
font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
font-size: 0.9rem;
}
.endpoint {
background: #f8f9fa;
border-left: 4px solid #000;
padding: 1rem;
margin: 1rem 0;
}
.method {
display: inline-block;
padding: 0.3rem 0.8rem;
border-radius: 3px;
font-weight: bold;
font-size: 0.8rem;
margin-right: 1rem;
}
.method.get { background: #28a745; color: white; }
.method.post { background: #007bff; color: white; }
.method.put { background: #ffc107; color: black; }
.method.delete { background: #dc3545; color: white; }
.grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
gap: 2rem;
margin: 2rem 0;
}
.card {
border: 1px solid #ddd;
border-radius: 8px;
padding: 1.5rem;
background: #fff;
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}
.card h4 {
margin-top: 0;
color: #000;
}
.badge {
display: inline-block;
padding: 0.3rem 0.6rem;
border-radius: 12px;
font-size: 0.8rem;
font-weight: bold;
margin-right: 0.5rem;
}
.badge.required { background: #dc3545; color: white; }
.badge.optional { background: #6c757d; color: white; }
.badge.array { background: #17a2b8; color: white; }
table {
width: 100%;
border-collapse: collapse;
margin: 1rem 0;
}
th, td {
padding: 0.75rem;
text-align: left;
border-bottom: 1px solid #ddd;
}
th {
background: #f8f9fa;
font-weight: 600;
color: #000;
}
.highlight {
background: #fff3cd;
border: 1px solid #ffeaa7;
border-radius: 4px;
padding: 1rem;
margin: 1rem 0;
}
.warning {
background: #f8d7da;
border: 1px solid #f5c6cb;
border-radius: 4px;
padding: 1rem;
margin: 1rem 0;
}
footer {
background: #000;
color: #fff;
text-align: center;
padding: 2rem 0;
margin-top: 4rem;
}
.toc {
background: #f8f9fa;
border: 1px solid #ddd;
border-radius: 8px;
padding: 1.5rem;
margin: 2rem 0;
}
.toc h3 {
margin-top: 0;
color: #000;
}
.toc ul {
list-style: none;
margin-left: 1rem;
}
.toc a {
color: #333;
text-decoration: none;
}
.toc a:hover {
color: #000;
text-decoration: underline;
}
</style>
</head>
<body>
<header>
<div class="container">
<h1>Image Search API</h1>
<p>Advanced semantic search for products using AI-powered image and text queries</p>
</div>
</header>
<nav>
<div class="container">
<ul>
<li><a href="#overview">Overview</a></li>
<li><a href="#quickstart">Quick Start</a></li>
<li><a href="#endpoints">API Endpoints</a></li>
<li><a href="#configuration">Configuration</a></li>
<li><a href="#examples">Examples</a></li>
<li><a href="#sdk">Python SDK</a></li>
</ul>
</div>
</nav>
<main>
<div class="container">
<section id="overview" class="section">
<h2>Overview</h2>
<p>The Image Search API provides powerful semantic search capabilities for product catalogs using state-of-the-art CLIP models and vector databases.</p>
<div class="grid">
<div class="card">
<h4>🔍 Image Search</h4>
<p>Upload product images to find visually similar items in your catalog</p>
</div>
<div class="card">
<h4>📝 Text Search</h4>
<p>Use natural language queries to discover products</p>
</div>
<div class="card">
<h4>🤖 AI-Powered</h4>
<p>Advanced CLIP models for superior understanding of images and text</p>
</div>
<div class="card">
<h4>⚡ Fast & Scalable</h4>
<p>Vector databases for lightning-fast search across millions of products</p>
</div>
</div>
<h3>Key Features</h3>
<ul>
<li><strong>Multi-modal Search:</strong> Search by image, text, or both</li>
<li><strong>Advanced Filtering:</strong> Filter by price, category, brand, and more</li>
<li><strong>Smart Reranking:</strong> AI-powered result optimization</li>
<li><strong>Multiple Vector Stores:</strong> ChromaDB, Pinecone, Qdrant, Weaviate, pgVector</li>
<li><strong>Database Flexibility:</strong> SQLite, PostgreSQL, MySQL support</li>
<li><strong>Auto-monitoring:</strong> Automatic indexing of new products</li>
</ul>
</section>
<section id="quickstart" class="section">
<h2>Quick Start</h2>
<div class="highlight">
<strong>🚀 Get started in 3 steps:</strong>
<ol>
<li>Configure your database and vector store</li>
<li>Run the setup script</li>
<li>Start the API</li>
</ol>
</div>
<h3>1. Configuration</h3>
<p>Copy the example configuration and customize it:</p>
<div class="code-block">
cp config.example.yaml config.yaml
# Edit config.yaml with your database settings
</div>
<h3>2. Setup</h3>
<div class="code-block">
# Validate configuration and test connections
python setup.py
</div>
<h3>3. Run</h3>
<div class="code-block">
# Start the API (automatically indexes your products)
python run.py
</div>
<p>Your API will be available at <code class="code-inline">http://localhost:8000</code></p>
</section>
<section id="endpoints" class="section">
<h2>API Endpoints</h2>
<div class="toc">
<h3>Table of Contents</h3>
<ul>
<li><a href="#search-endpoint">Search Products</a></li>
<li><a href="#products-endpoints">Product Management</a></li>
<li><a href="#admin-endpoints">Administration</a></li>
<li><a href="#health-endpoints">Health & Monitoring</a></li>
</ul>
</div>
<h3 id="search-endpoint">Search Products</h3>
<div class="endpoint">
<span class="method post">POST</span>
<strong>/search</strong>
<p>Search for products using image upload or text query</p>
<h4>Parameters</h4>
<table>
<tr>
<th>Parameter</th>
<th>Type</th>
<th>Required</th>
<th>Description</th>
</tr>
<tr>
<td>file</td>
<td>File</td>
<td><span class="badge optional">Optional</span></td>
<td>Image file to search with</td>
</tr>
<tr>
<td>query</td>
<td>String</td>
<td><span class="badge optional">Optional</span></td>
<td>Text query for search</td>
</tr>
<tr>
<td>top_k</td>
<td>Integer</td>
<td><span class="badge optional">Optional</span></td>
<td>Number of results to return (default: 10)</td>
</tr>
<tr>
<td>min_price</td>
<td>Float</td>
<td><span class="badge optional">Optional</span></td>
<td>Minimum price filter</td>
</tr>
<tr>
<td>max_price</td>
<td>Float</td>
<td><span class="badge optional">Optional</span></td>
<td>Maximum price filter</td>
</tr>
<tr>
<td>title_substr</td>
<td>String</td>
<td><span class="badge optional">Optional</span></td>
<td>Title substring filter</td>
</tr>
</table>
<h4>Example Request</h4>
<div class="code-block">
# Image search
curl -X POST "http://localhost:8000/search" \
-F "file=@product.jpg" \
-F "top_k=5"
# Text search
curl -X POST "http://localhost:8000/search" \
-F "query=wireless headphones" \
-F "top_k=10" \
-F "min_price=50" \
-F "max_price=200"
</div>
<h4>Response</h4>
<div class="code-block">
{
"results": [
{
"id": "prod_123",
"title": "Wireless Bluetooth Headphones",
"image_url": "https://example.com/headphones.jpg",
"price": 99.99,
"category": "Electronics",
"brand": "TechBrand",
"score": 0.95,
"rank": 1
}
],
"latency_ms": 45
}
</div>
</div>
<h3 id="products-endpoints">Product Management</h3>
<div class="endpoint">
<span class="method get">GET</span>
<strong>/products</strong>
<p>Get list of products with optional filtering</p>
<h4>Query Parameters</h4>
<table>
<tr>
<th>Parameter</th>
<th>Type</th>
<th>Description</th>
</tr>
<tr>
<td>limit</td>
<td>Integer</td>
<td>Number of products to return (default: 20, max: 100)</td>
</tr>
<tr>
<td>offset</td>
<td>Integer</td>
<td>Number of products to skip (default: 0)</td>
</tr>
<tr>
<td>category</td>
<td>String</td>
<td>Filter by category</td>
</tr>
<tr>
<td>brand</td>
<td>String</td>
<td>Filter by brand</td>
</tr>
<tr>
<td>min_price</td>
<td>Float</td>
<td>Minimum price filter</td>
</tr>
<tr>
<td>max_price</td>
<td>Float</td>
<td>Maximum price filter</td>
</tr>
</table>
</div>
<div class="endpoint">
<span class="method get">GET</span>
<strong>/products/{product_id}</strong>
<p>Get a specific product by ID</p>
</div>
<div class="endpoint">
<span class="method post">POST</span>
<strong>/products</strong>
<p>Create a new product (requires admin token)</p>
</div>
<div class="endpoint">
<span class="method put">PUT</span>
<strong>/products/{product_id}</strong>
<p>Update an existing product (requires admin token)</p>
</div>
<div class="endpoint">
<span class="method delete">DELETE</span>
<strong>/products/{product_id}</strong>
<p>Delete a product (requires admin token)</p>
</div>
<h3 id="admin-endpoints">Administration</h3>
<div class="endpoint">
<span class="method get">GET</span>
<strong>/admin/stats</strong>
<p>Get database and system statistics (requires admin token)</p>
</div>
<div class="endpoint">
<span class="method get">GET</span>
<strong>/admin/metrics</strong>
<p>Get search performance metrics (requires admin token)</p>
</div>
<div class="endpoint">
<span class="method post">POST</span>
<strong>/admin/reindex</strong>
<p>Trigger reindexing of all products (requires admin token)</p>
</div>
<h3 id="health-endpoints">Health & Monitoring</h3>
<div class="endpoint">
<span class="method get">GET</span>
<strong>/health</strong>
<p>Check system health and status</p>
</div>
<div class="endpoint">
<span class="method get">GET</span>
<strong>/metrics</strong>
<p>Get Prometheus-format metrics</p>
</div>
</section>
<section id="configuration" class="section">
<h2>Configuration</h2>
<p>The API uses a YAML configuration file to specify database connections, vector store settings, and other options.</p>
<h3>Configuration File Structure</h3>
<div class="code-block">
# Database Configuration
database:
type: sqlite # sqlite, postgresql, mysql
connection_string: "sqlite:///./my_products.db"
table_name: "products"
columns:
id: "product_id"
title: "name"
image_url: "image"
category: "category"
brand: "brand"
price: "price"
rating: "rating"
description: "description"
# Vector Store Configuration
vector_store:
type: chromadb # chromadb, pinecone, qdrant, weaviate, pgvector
collection_name: "product_embeddings"
chromadb:
mode: persistent
path: "./data/chroma_db"
# AI Configuration
ai:
clip_model: "clip-ViT-L-14" # or clip-ViT-B-32
# API Configuration
api:
host: "0.0.0.0"
port: 8000
reload: false
# Auto-monitoring
monitoring:
enabled: true
interval: 60 # seconds
</div>
<h3>Supported Databases</h3>
<table>
<tr>
<th>Database</th>
<th>Connection String Format</th>
<th>Best For</th>
</tr>
<tr>
<td>SQLite</td>
<td><code>sqlite:///./database.db</code></td>
<td>Development, small catalogs</td>
</tr>
<tr>
<td>PostgreSQL</td>
<td><code>postgresql://user:pass@host:port/db</code></td>
<td>Production, large catalogs</td>
</tr>
<tr>
<td>MySQL</td>
<td><code>mysql://user:pass@host:port/db</code></td>
<td>Production, existing MySQL setups</td>
</tr>
</table>
<h3>Supported Vector Stores</h3>
<table>
<tr>
<th>Vector Store</th>
<th>Type</th>
<th>Best For</th>
</tr>
<tr>
<td>ChromaDB</td>
<td><code>chromadb</code></td>
<td>Development, small catalogs</td>
</tr>
<tr>
<td>Pinecone</td>
<td><code>pinecone</code></td>
<td>Production, managed service</td>
</tr>
<tr>
<td>Qdrant</td>
<td><code>qdrant</code></td>
<td>Self-hosted, production</td>
</tr>
<tr>
<td>Weaviate</td>
<td><code>weaviate</code></td>
<td>Self-hosted, production</td>
</tr>
<tr>
<td>pgVector</td>
<td><code>pgvector</code></td>
<td>PostgreSQL integration</td>
</tr>
</table>
</section>
<section id="examples" class="section">
<h2>Examples</h2>
<h3>Python Client Example</h3>
<div class="code-block">
import requests
# Search by image
with open('product.jpg', 'rb') as f:
response = requests.post('http://localhost:8000/search',
files={'file': f},
data={'top_k': 5})
# Search by text
response = requests.post('http://localhost:8000/search',
data={'query': 'wireless headphones',
'top_k': 10,
'min_price': 50,
'max_price': 200})
results = response.json()['results']
for product in results:
print(f"{product['title']} - ${product['price']} (Score: {product['score']:.3f})")
</div>
<h3>JavaScript/Node.js Example</h3>
<div class="code-block">
const FormData = require('form-data');
const fs = require('fs');
// Search by image
const form = new FormData();
form.append('file', fs.createReadStream('product.jpg'));
form.append('top_k', '5');
fetch('http://localhost:8000/search', {
method: 'POST',
body: form
})
.then(response => response.json())
.then(data => {
console.log('Search results:', data.results);
});
// Search by text
fetch('http://localhost:8000/search', {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
},
body: 'query=wireless headphones&top_k=10&min_price=50&max_price=200'
})
.then(response => response.json())
.then(data => {
console.log('Search results:', data.results);
});
</div>
<h3>cURL Examples</h3>
<div class="code-block">
# Image search
curl -X POST "http://localhost:8000/search" \
-F "file=@product.jpg" \
-F "top_k=5"
# Text search with filters
curl -X POST "http://localhost:8000/search" \
-F "query=wireless headphones" \
-F "top_k=10" \
-F "min_price=50" \
-F "max_price=200"
# Get product list
curl "http://localhost:8000/products?limit=20&category=Electronics"
# Health check
curl "http://localhost:8000/health"
</div>
</section>
<section id="sdk" class="section">
<h2>Python SDK</h2>
<p>The Image Search SDK provides a Python client for easy integration with your applications.</p>
<h3>Installation</h3>
<div class="code-block">
pip install image-search-sdk
</div>
<h3>Quick Start</h3>
<div class="code-block">
from image_search_sdk import ImageSearchClient, Product, SearchOptions
# Initialize client
client = ImageSearchClient(
data_dir="./my_data",
model_name="clip-ViT-L-14",
vector_store_type="chromadb",
vector_store_config={
"mode": "persistent",
"path": "./data/chroma"
}
)
# Connect to your database
client.connect_database(
connection_string="sqlite:///products.db",
table_name="products",
id_column="product_id",
title_column="name",
image_url_column="image"
)
# Initialize embeddings
stats = client.initialize()
print(f"Indexed {stats['indexed_products']} products")
# Search by image
results = client.search_by_image("query.jpg", SearchOptions(top_k=5))
# Search by text
results = client.search_by_text("wireless headphones", SearchOptions(top_k=10))
# Add new product
new_product = Product(
id="prod_123",
title="New Product",
image_url="https://example.com/image.jpg",
category="Electronics",
price=99.99
)
client.add_product(new_product)
</div>
<h3>SDK Features</h3>
<ul>
<li><strong>Local Processing:</strong> No API calls - everything runs locally</li>
<li><strong>Multiple Vector Stores:</strong> ChromaDB, Pinecone, Qdrant, Weaviate, pgVector</li>
<li><strong>Database Flexibility:</strong> Works with any SQL database</li>
<li><strong>Auto-monitoring:</strong> Automatically index new products</li>
<li><strong>Schema Mapping:</strong> Flexible column mapping for any database schema</li>
</ul>
<h3>Configuration Examples</h3>
<h4>ChromaDB (Local Development)</h4>
<div class="code-block">
client = ImageSearchClient(
vector_store_type="chromadb",
vector_store_config={
"mode": "persistent",
"path": "./data/chroma"
}
)
</div>
<h4>Pinecone (Production)</h4>
<div class="code-block">
client = ImageSearchClient(
vector_store_type="pinecone",
vector_store_config={
"api_key": "your-pinecone-key",
"environment": "us-west1-gcp",
"index_name": "product-search"
}
)
</div>
<h4>Qdrant (Self-hosted)</h4>
<div class="code-block">
client = ImageSearchClient(
vector_store_type="qdrant",
vector_store_config={
"mode": "server",
"host": "localhost",
"port": 6333,
"api_key": "your-qdrant-key"
}
)
</div>
</section>
</div>
</main>
<footer>
<div class="container">
<p>© 2024 Image Search API. Built with FastAPI, CLIP, and Vector Databases.</p>
</div>
</footer>
</body>
</html>
|