← Latest Blog Posts

🎵 Spotify Podcast

Vector search has revolutionized how we interact with Artificial Intelligence, allowing systems to understand the meaning behind data, rather than just searching for keywords. This technology has transformed areas such as recommendation systems, chatbots, and, most notably, Retrieval Augmented Generation (RAG) pipelines.

However, transforming a vector search prototype into a robust, scalable, and economically viable production system is a complex challenge. Crucial issues such as model selection, ensuring high availability, optimizing costs and minimizing latency, as well as the relevance of the results, become priorities.

This article explores a common question: the implementation of a "fallback" for a primary embedding service, such as the OpenAI API, using an open-source model like all-MiniLM-L6-v2. An in-depth analysis of this proposal reveals misconceptions about the nature of embeddings and serves as a starting point for a comprehensive guide on best practices for building resilient and high-performance vector search systems.

Our goal is to provide a strategic roadmap for AI developers and engineers. Deconstructing an unfeasible fallback architecture, we will explore the correct patterns for high availability, compare costs and performance between proprietary APIs and self-hosted models, and detail advanced optimization and retrieval techniques – such as hybrid search and rerankers – essential to achieve superior search relevance.

The fallback strategy, although prudent in software engineering, faces unique challenges in the context of text embeddings. The idea of using all-MiniLM-L6-v2 as a substitute for OpenAI's text-embedding-3-small is, in practice, unfeasible due to the fundamental incompatibility between vector spaces.

Each embedding model creates its own vector space, mapping semantic concepts to unique numerical representations. This means that vectors generated by different models are incomparable, even for the same text. Using one model for the query and another for the database is like trying to find an address in São Paulo using a map of Lisbon.

The difference in vector dimensions (1536 for text-embedding-3-small and 384 for all-MiniLM-L6-v2) is just a symptom of this incompatibility. Even different models from the same vendor can generate incompatible vectors, requiring complete reindexing of the database.

Therefore, the proposed fallback architecture is not only a bad practice, but impossible. Resilience lies not in a "fallback model," but in a "fallback infrastructure." Instead of focusing on inferior alternative models, we should prioritize building a resilient architecture around the chosen model, whether proprietary or open-source.

The solution to the concern about OpenAI API unavailability lies in a robust retry logic on the client side (with exponential backoff) and, if applicable, in configuring redundancy between different geographical regions. If the option is to migrate to a self-hosted model, the complete solution involves deploying redundant instances of the inference model and the vector database, managed by a load balancer and a replication/failover system.

To ensure service continuity, the key is redundancy. Instead of replacing one component with a different one, the ideal is to replicate the same component. A high-availability system eliminates single points of failure, ensuring that if one instance fails, another identical instance takes over the workload with minimal disruption. This translates into redundancy in both the inference service (with load balancing) and the vector database (with master-slave or cluster replication).

The decision between consuming an embedding model as a service (API) or hosting it in your own infrastructure is crucial. APIs offer simplicity, but self-hosting becomes more advantageous at scale, offering better cost-effectiveness, lower latency, and greater control over data. The financial break-even point is reached faster than one might think, making self-hosting a strategic upgrade for production applications.

Once self-hosting is chosen, optimization is essential. Model quantization (reducing the numerical precision of weights) and the use of specialized inference servers, such as the NVIDIA Triton Inference Server, are essential to maximize performance and cost-effectiveness.

Beyond infrastructure, the relevance of results is crucial. Pure vector search has limitations. Hybrid search, which combines the semantic understanding of vector search with the lexical precision of keyword search (BM25), offers superior results. Fusing results with Reciprocal Rank Fusion (RRF) and reclassification with cross-encoder models elevate precision to a cutting-edge level. For specific domains, fine-tuning the embedding model on your own data is the final step for maximum relevance.