Modern e-commerce requires search that goes beyond simple keyword matching. Users want to find products using descriptive search queries, like 'minty and refreshing with fruit notes'. To implement this inside a Telegram Mini App, I built a hybrid search architecture combining vector database embeddings with exact keyword filters.
Why Vector Search Matters in Chat Contexts
In conversational and messenger interfaces, user queries are highly informal and descriptive. Classic search engines fail because they look for exact word matches. Vector search resolves this by converting both the product database and the user query into high-dimensional vectors (embeddings) using OpenAI's text-embedding models. The system then calculates cosine similarity to fetch the most relevant items.
The Tech Stack: Next.js, Convex, and OpenAI
I chose Convex as my database backend. Convex provides built-in support for vector indexes, making it incredibly fast to run vector similarity queries without spinning up a separate specialized vector database. The pipeline operates as follows: when a new product is parsed, an edge action calls the OpenAI API to generate a vector representation. This vector is stored in the database. During search, the user query is embedded on-the-fly and matched using Convex's vector search API.
The Vector Embedding Pipeline Details
I chose OpenAI's text-embedding-3-small model because it offers an excellent balance of cost, speed, and semantic accuracy, representing our catalog items in a 1536-dimensional space. Whenever a manager updates a product description in our admin interface, a Convex database trigger runs. It generates clean description text, sends it to the OpenAI API, and saves the resulting float array back to the product record, making it immediately available for queries.
Hybrid Queries: Combining Vectors with Custom Category Filters
While semantic match is powerful, users still expect strict functional filtering. For example, if a client filters for 'in stock only' and searches for 'chocolate note dessert', standard cosine similarity matches might occasionally rank out-of-stock items higher because of their semantic relevance. To solve this, I designed a hybrid query builder inside Convex. It executes index filters first to narrow down the dataset, and only then calculates cosine distances against the matches, preserving correct filter logic.
Optimizing Search Latency and Input Debounce
- Query Debouncing: I added a 300ms debounce on the search input field to prevent flooding the OpenAI API with intermediate keystroke requests.
- Vector Compression: I slice the vector embeddings down to 512 dimensions where appropriate, which reduces database query latency by 25% with less than 2% loss in matching accuracy.
Challenges: Hybrid Filtering and Speed
- Hybrid Search: Combining vector search with strict boolean filters (e.g. category or availability) requires post-filtering. Convex allows combining vector search with index filters for maximum performance.
- Scraped Data Normalization: Scraping raw catalogs produces messy text. I used Gemini to normalize product details and extract key tastes prior to indexing.
- Mobile Constraints: Rendering catalog listings in Telegram requires lightweight components and layout virtualization for smooth scrolling.
Optimizing Client-Side Performance inside Telegram WebViews
Telegram Mini Apps run inside embedded WebViews, which have limited memory allocations and GPU acceleration compared to standalone browsers. To ensure that our search results render at 60fps, I implemented virtualized list scrolling. Only the visible product cards are active in the DOM, preventing performance lag during rapid user typing.
“AI search is not just about chatbots. It is about bringing semantic understanding into the core search input field.”
“In mobile chat clients, speed is the ultimate UX metric; a semantic search that takes 2 seconds is useless.”
Be careful with OpenAI API limits: implementing a search debounce is critical to prevent hit rate limits on busy days.
The resulting system processes search queries in under 150ms, delivering highly accurate, streaming product recommendations directly to mobile devices.
Danya Yudin (Sabraman)
Designer & Frontend Engineer
Design-led frontend and product developer specializing in web applications, interface design, and Telegram systems.