Skip to main content

On This Page

Implementing AI Image Search in Telegram Marketplaces using SigLIP and Qdrant

2 min read
Share

These articles are AI-generated summaries. Please check the original sources for full details.

How I Added AI Image Search to a Marketplace Bot (And Why It Changed Everything)

Developer David integrated Google’s SigLIP model into a Telegram marketplace bot to solve the limitations of keyword-based search. The system utilizes INT8 dynamic quantization to perform high-dimensional vector searches on a $9/month VPS.

Why This Matters

While text search relies on matching vocabularies between buyers and sellers, visual search bridges the gap by using semantic embeddings. In a production environment with limited resources, standard PyTorch models are often too bulky for deployment, requiring ONNX quantization to reduce the vision model from 355MB to 97MB while maintaining 100% agreement on critical tasks like NSFW detection.

Key Insights

  • SigLIP vision-language models generate 1152-dimensional vectors to represent images mathematically, enabling conceptual matching over simple pixel comparison.
  • Qdrant vector database allows for sub-second similarity searches using cosine similarity, utilizing a 0.75 score threshold to filter relevant results.
  • ONNX dynamic quantization reduced the vision model size by 3.7x and the text model by 2.4x, resulting in a 2x inference speed increase on modest hardware.
  • Reusing the SigLIP text encoder enables multi-purpose functionality, powering both semantic text search and automated NSFW filtering without additional models.
  • Visual indexing bypasses the need for detailed text descriptions, allowing products with minimal metadata to be discovered by buyers through image similarity.

Working Examples

Simplified search implementation using Qdrant vector database and SigLIP embeddings.

async def search_by_image(photo_bytes: bytes) -> list[Product]:
    # Convert photo to embedding
    embedding = await image_service.encode_image(photo_bytes)
    # Find similar products in vector DB
    results = await qdrant_client.search(
        collection_name="products",
        query_vector=embedding,
        limit=10,
        score_threshold=0.75 # Only return reasonably similar results
    )
    return [await get_product(r.id) for r in results]

ONNX INT8 dynamic quantization process used to optimize model size for production VPS deployment.

from onnxruntime.quantization import quantize_dynamic, QuantType
quantize_dynamic(
    model_input="vision_model.onnx",
    model_output="vision_int8.onnx",
    weight_type=QuantType.QUInt8,
    op_types_to_quantize=["MatMul", "Gemm"]
)

Practical Applications

  • Marketplace systems like the k4pi_bot use visual search to allow buyers to find items via screenshots or Pinterest photos. Pitfall: High bounce rates occur if the system lacks a sufficiently large indexed catalog during the ‘cold start’ phase.
  • Automated moderation workflows use text-to-image similarity to score uploads against unsafe prompts. Pitfall: Setting similarity thresholds too loose results in showing irrelevant products, while too strict thresholds return zero results.

References:

Continue reading

Next article

ctx CLI: Automating Project Context for AI Development Workflows

Related Content