Spaces:
Sleeping
Sleeping
File size: 2,668 Bytes
a475b1f | 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 | """
Quick Start Example - Minimal setup to get started with the SDK.
This example shows the fastest way to integrate the Image Search SDK
into your application with minimal configuration.
"""
import sys
from pathlib import Path
# Add SDK to path
sdk_path = Path(__file__).parent.parent
sys.path.insert(0, str(sdk_path))
from image_search_sdk import ImageSearchClient, Product, SearchOptions
def main():
print("Quick Start Example - Image Search SDK")
print("=" * 60)
# Step 1: Initialize the SDK client
print("\n1. Initializing SDK...")
client = ImageSearchClient(
data_dir="./quick_start_data",
model_name="clip-ViT-L-14", # High-quality model
vector_store_type="chromadb", # Simple local storage
vector_store_config={
"mode": "persistent",
"path": "./quick_start_data/chroma"
}
)
print(" ✓ SDK initialized")
# Step 2: Connect to your product database
print("\n2. Connecting to database...")
client.connect_database(
connection_string="sqlite:///your_products.db", # Replace with your DB
table_name="products",
id_column="id",
title_column="name", # Map your column names
image_url_column="image"
)
print(" ✓ Database connected")
# Step 3: First-time initialization (generates embeddings)
print("\n3. Initializing embeddings...")
stats = client.initialize(batch_size=50)
print(f" ✓ Indexed {stats['indexed_products']} products in {stats['duration_seconds']:.1f}s")
# Step 4: Enable automatic embedding generation for new products
print("\n4. Enabling auto-monitor...")
client.enable_auto_monitor(poll_interval=60, enable=True)
print(" ✓ Auto-monitor enabled (checks every 60s)")
# Step 5: Search!
print("\n5. Testing search...")
# Search by text
results = client.search_by_text("blue shirt", options=SearchOptions(top_k=5))
print(f"\n Found {len(results)} results for 'blue shirt':")
for i, result in enumerate(results, 1):
print(f" {i}. {result.product.title} (score: {result.similarity_score:.3f})")
# Search by image (if you have a local image)
# results = client.search_by_image("./sample_image.jpg", options=SearchOptions(top_k=5))
print("\n" + "=" * 60)
print("Setup complete! Your image search is now running.")
print("=" * 60)
# Keep running (auto-monitor is active in background)
try:
input("\nPress Enter to exit...")
finally:
client.close()
print("Shutdown complete.")
if __name__ == "__main__":
main()
|