惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Recent Commits to openclaw:main
Recent Commits to openclaw:main
N
News | PayPal Newsroom
TaoSecurity Blog
TaoSecurity Blog
Google Online Security Blog
Google Online Security Blog
NISL@THU
NISL@THU
T
Threatpost
C
CXSECURITY Database RSS Feed - CXSecurity.com
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
Engineering at Meta
Engineering at Meta
AWS News Blog
AWS News Blog
D
Darknet – Hacking Tools, Hacker News & Cyber Security
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
P
Privacy International News Feed
B
Blog
PCI Perspectives
PCI Perspectives
Martin Fowler
Martin Fowler
Spread Privacy
Spread Privacy
P
Proofpoint News Feed
T
Tenable Blog
F
Fortinet All Blogs
G
GRAHAM CLULEY
V2EX - 技术
V2EX - 技术
C
Check Point Blog
Project Zero
Project Zero
P
Palo Alto Networks Blog
J
Java Code Geeks
W
WeLiveSecurity
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
T
The Exploit Database - CXSecurity.com
博客园 - 司徒正美
P
Privacy & Cybersecurity Law Blog
S
SegmentFault 最新的问题
Last Week in AI
Last Week in AI
Forbes - Security
Forbes - Security
C
Cybersecurity and Infrastructure Security Agency CISA
Security Latest
Security Latest
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
Vercel News
Vercel News
Recent Announcements
Recent Announcements
博客园 - Franky
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
Recorded Future
Recorded Future
The Last Watchdog
The Last Watchdog
MongoDB | Blog
MongoDB | Blog
人人都是产品经理
人人都是产品经理
酷 壳 – CoolShell
酷 壳 – CoolShell
Cisco Talos Blog
Cisco Talos Blog
量子位
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC

Ubuntu blog

Tracing a memory leak bug in PID 1 and contributing an upstream fix: a Linux support story | Ubuntu MAAS installation: bare metal provisioning is easier than ever | Ubuntu Januscape vulnerability CVE-2026-53359 mitigations available | Ubuntu Managing Ubuntu on bare metal at scale Ubuntu Server: a platform made for enterprise scale | Ubuntu Building an open source chain of trust: new research uncovers key blockers and ways forward | Ubuntu Beyond safety and security: Why automotive open source demands dependability  | Ubuntu DirtyClone Linux kernel local privilege escalation vulnerability fixes available | Ubuntu pedit COW kernel local privilege escalation vulnerability mitigations | Ubuntu Canonical becomes Gold Sponsor of Trifecta Tech Foundation | Ubuntu Challenges designers face in open source (and how to fix them) | Ubuntu Hunting a 16-year-old SQLite bug with TLA+: is dqlite affected? | Ubuntu Anbox Cloud on C4A metal: Android, at scale, without friction | Ubuntu Canonical announces live kernel patching for Arm64 | Ubuntu How to use RISC-V custom instructions with Ubuntu | Ubuntu Ubuntu Summit 26.04: connected by open source | Ubuntu So you need to add microcontrollers to your fleet: now what? | Ubuntu Validating real-world skills through Canonical Academy | Ubuntu Virtualized Android comes to Anbox Cloud | Ubuntu Template: Streamlining open source design contributions | Ubuntu Beyond Mythos: responding to a new threat landscape | Ubuntu A look into Ubuntu Core 26: Building a local AI inference appliance in a virtual machine | Ubuntu A decade of Ubuntu on IBM Z and IBM LinuxONE | Ubuntu AI at the edge: simplifying infrastructure with Cisco and Canonical | Ubuntu The next era of telco clouds: get open infrastructure choice with Sylva and Canonical Kubernetes | Ubuntu What is RDMA over Converged Ethernet (RoCE)? | Ubuntu Beyond tokens per watt – using Ubuntu 26.04 LTS for AI | Ubuntu A look into Ubuntu Core 26: Deploying AI models on Renesas RZ/V series for production | Ubuntu RISC-V profiles – why is RVA23 significant? | Ubuntu AI with AMD ROCm on Ubuntu: your questions answered | Ubuntu Ubuntu and Ubuntu Pro on Azure Cobalt 200 VMs | Ubuntu What is InfiniBand? | Ubuntu How Canonical Support solves hard Linux performance bugs  – even in 12-year old code | Ubuntu Securing AI agent workflows on Ubuntu with the new NVIDIA OpenShell snap | Ubuntu Canonical announces optimized Ubuntu images for TPU virtual machines by Google Cloud | Ubuntu VMware hypervisor deployment using MAAS | Ubuntu Migrating from Apache Spark 3 to Spark 4 | Ubuntu Introducing Workshop: launch sandboxed development environments on Ubuntu with a single command | Ubuntu Run agentic workloads on Arm and Ubuntu | Ubuntu Decoding design: How design and engineering thrive together in open source | Ubuntu Developing web apps with local LLM inference | Ubuntu PinTheft Linux kernel vulnerability mitigation | Ubuntu Canonical announces fully Managed Kubeflow AI operations platform on the Microsoft Azure Marketplace | Ubuntu A look into Ubuntu Core 26: Cloud-powered edge computing with AWS IoT Greengrass and Azure IoT Edge | Ubuntu CVE-2026-46333 (ssh-keysign-pwn) Linux kernel vulnerability mitigations | Ubuntu Finding the blind spot: How Canonical hunts logic flaws with AI | Ubuntu Fragnesia Linux kernel local privilege escalation vulnerability mitigations | Ubuntu Rethinking BYOD security: protecting data without trusting devices | Ubuntu Dirty Frag Linux kernel local privilege escalation vulnerability mitigations | Ubuntu Three weeks to go: A sneak peek of the Ubuntu Summit 26.04 experience | Ubuntu How to use Ubuntu on Windows | Ubuntu Fixes available for CVE-2026-31431 (Copy Fail) Linux Kernel Local Privilege Escalation Vulnerability | Ubuntu Run NVIDIA Nemotron 3 Nano Omni locally in a single command | Ubuntu Why Web Engineering is great | Ubuntu Ubuntu 16.04 LTS has reached the end of standard Expanded Security Maintenance with Ubuntu Pro. Here are your options. | Ubuntu Understanding disaggregated GenAI model serving with llm-d | Ubuntu From Jammy to Resolute: how Ubuntu’s toolchains have evolved | Ubuntu Canonical expands Ubuntu support to next-generation MediaTek Genio 520 and 720 platforms | Ubuntu Intentional leadership at Canonical | Ubuntu Ubuntu Pro comes to Nutanix bare-metal Kubernetes | Ubuntu RISC-V 101 – what is it and what does it mean for Canonical? | Ubuntu Ubuntu Summit 26.04 is coming: Save the date and share your story! | Ubuntu How to manage Ubuntu fleets using on-premises Active Directory and ADSys | Ubuntu Simplify bare metal operations for sovereign clouds | Ubuntu How to Harden Ubuntu SSH: From static keys to cloud identity | Ubuntu The “scanner report has to be green” trap | Ubuntu Modern Linux identity management: from local auth to the cloud with Ubuntu | Ubuntu Canonical welcomes NVIDIA’s donation of the GPU DRA driver to CNCF | Ubuntu Hot code burns: the supply chain case for letting your containers cool before you ship | Ubuntu
Hybrid search and reranking: a deeper look at RAG | Ubuntu
robgibbon (r · 2026-04-20 · via Ubuntu blog

Many of us are familiar with the retrieval augmented generative AI (RAG) pattern for building agentic AI applications – like digital concierges, frontline support chatbots and agents that can help with basic self-service troubleshooting. 

At a high level, the flow for RAG is fairly clear – the user’s prompt is augmented with some relevant contextual information from a knowledge base, and the large language model (LLM) provides the user with a response on the basis of the information provided, instead of from the “baked in” information that it was originally trained on.

In this article, we’ll roll up our sleeves and dive a little deeper to try to get a better grasp of how typical production-grade RAG systems actually work. To understand what’s really going on in the information retrieval process, we need to dig into hybrid search and reranking.

Embeddings and vector search

Before we get to hybrid search and reranking, let’s establish some baseline RAG understanding. Vector databases essentially provide a geometry based search index that can help to find relevant content – or knowledge – in our knowledge base. The way it works is this:

  1. The underlying source data is encoded into embeddings using a specialized, GPU accelerated AI model. These embeddings are represented as vectors – a list of numbers where each number represents a coordinate in a high-dimensional space.
  2. These embeddings are stored in a database table, and typically a special database index is then precomputed using a search engine specialised in vector searches, to help speed things up.
  3. Then, at runtime, the “distance” between two concepts can be calculated using one of various mathematical metrics – for example, cosine similarity, Euclidian distance (L2 search) and others.
  4. When the search runs, the results return the closest matching vectors, mapped back to records in the underlying source data. That could be text chunks, (or if using a multi-modal language model) it could be images, audio recordings, PDF documents, and so on. We’ll stick with text chunks in this article, to keep it simple.

The results of the vector search will be text chunks from the raw source data, which will be sent to the LLM along with the user’s prompt. The encoded vector embeddings help to find the right information in the knowledge base, but LLMs can’t interpret those vector embeddings directly.

  1. Search: Your query is converted into a vector to find matching pieces of data in the database.
  2. Retrieval: The database pulls the original text associated with those matching vectors.
  3. Augmentation: That text is inserted into a prompt template (e.g., “Using this info: [Source Text], answer the question: [User Prompt]”).
  4. Generation: This combined text prompt is sent to the LLM.

It’s important to note that first step. When you run the search, the user’s prompt has to be converted to vectors too, at runtime. This is so that the vector search engine can compare the vectors in the prompt with the vectors in the database and find the nearest matches.

In order to get meaningful results, you need to use the same embedding model as you used when you created the vector index in the database. This is because each model creates its own unique “map” of meaning (often called a vector space). Using a different embedding model is a silent killer – the application will run without errors, but the information retrieved will be completely irrelevant.

So that’s vector search. But, to make a RAG system production-ready, you typically need to move beyond “naive” vector search to a multi-stage retrieval process.

Hybrid search

Hybrid search runs both vector search and full text search algorithms in parallel and merges their results.

  • Vector search (dense) is good at finding “meaning.” If you search for “sunny weather,” it might find “clear blue skies” even though the words don’t match.
  • Full-text search (sparse) is good at finding “exact matches.” It uses a text matching algorithm like best match 25 (BM25) to find specific product IDs, acronyms, or rare technical terms that vector models sometimes can’t differentiate.

These two methods use different scoring systems (0.0 to 1.0 for vectors vs. unbounded scores for BM25). Thus they’re combined using an algorithm like reciprocal rank fusion (RRF). RRF looks at the position of a document in both lists rather than the raw score, giving a higher final rank to documents that appear near the top of both.

Calculating the combined score

There are actually two approaches that are typically found for calculating the combined ranking score.

Reciprocal rank fusion (RRF)

RRF ignores the raw scores entirely and only looks at the rank (1st, 2nd, 3rd, etc.) of the document in each list. RRF uses a smoothing factor – typically this is set to the whole number `60`. This standard “smoothing” factor prevents a single very high rank in one search from completely drowning out a moderate rank in the other.

Relative score fusion (weighted average)

This method keeps the raw scores but normalizes them first.

  1. Both the BM25 and Vector scores are scaled to a 0–1 range
  2. A weighting parameter is applied to decide which search method you trust more.

RRF doesn’t need much tweaking and is pretty robust, while weighted average can give more surgical control if you know your keyword search is consistently more reliable than your vector search (or vice-versa).

Hybrid search in the database

In modern RAG stacks, the fusion of full text keyword search (BM25) and vector search is increasingly moving into the database layer to reduce latency and “glue code” – middleware logic which might otherwise increase the overall management complexity of the solution.

  • For PostgreSQL (pgvector and `full-text`) you can write a single SQL query or stored procedure that runs two subqueries – one for the vector distance and one for the tsvector keyword match – and then applies the RRF formula to the results.
  • Some databases like OpenSearch provide built-in functions that handle the RRF calculation for you automatically.

PostgreSQL hybrid search with RRF

Let’s see what hybrid search might look like in PostgreSQL. This example assumes you have a table called documents with a content column (for text search) and an embedding column (for vector search).

WITH 
-- 1. Semantic Search: Rank by vector similarity
semantic_search AS (
  SELECT id, ROW_NUMBER() OVER (ORDER BY embedding <=> '[0.1, -0.2, ...]'::vector) as rank
  FROM documents
  ORDER BY embedding <=> '[0.1, -0.2, ...]'::vector
  LIMIT 50
),
-- 2. Keyword Search: Rank by text relevance (BM25 or ts_rank)
keyword_search AS (
  SELECT id, ROW_NUMBER() OVER (ORDER BY ts_rank_cd(to_tsvector('english', content), query) DESC) as rank
  FROM documents, plainto_tsquery('english', 'your search terms') query
  WHERE to_tsvector('english', content) @@ query
  LIMIT 50
),
-- 3. Fusion: Combine ranks using the RRF formula: 1 / (rank + k)
combined_results AS (
  SELECT id, 1.0 / (60 + s.rank) as score FROM semantic_search s
  UNION ALL
  SELECT id, 1.0 / (60 + k.rank) as score FROM keyword_search k
)
-- 4. Final Output: Sum scores for items found in both/either list
SELECT d.id, d.content, SUM(c.score) as final_rrf_score
FROM combined_results c
JOIN documents d ON c.id = d.id
GROUP BY d.id, d.content
ORDER BY final_rrf_score DESC
LIMIT 10;

The benefits of running this in a stored procedure inside the database are

  • Performance: By doing the fusion in the database, you only return the final 10 rows to your application instead of two large lists of 50.
  • Simplicity: You don’t have to write logic in your application middleware to “match” IDs from two different arrays.

You might be wondering about some of the unusual operators and datatypes used in the above code listing. The `<=>` operator is pg_vector’s cosine distance operator, used to calculate the distance between two vectors. The `[0.1, 0.2 … ]` signifies an example of how a vector is represented. On the other hand, `@@` is the operator used by the full text search engine to check for a match between the search query and a field.

Reranking

A reranker is a second-stage AI model that improves the accuracy of the contextual information that gets sent to the LLM along with the user’s prompt. While vector search is fast but fuzzy, a reranker is slower but more accurate.

For reranking, you don’t need to encode the data into embeddings. Instead, you send the raw text of the query and the raw text of the result chunks directly to the reranker model.

The workflow is:

  1. Recall: you perform a hybrid search and grab a relatively large candidate resultset (e.g., the top 50–100 chunks).
  2. Rerank: you send the user prompt together with those top candidate chunks to a reranking model. Unlike vector models, a reranker looks at the query and the document together to see how well they actually fit.
  3. Final Selection: you take only the top 5–10 results from the reranker and send those to the LLM.

How reranking works

A reranking model is typically a cross-encoder. Unlike the embedding models (bi-encoders) used for the initial search, a cross-encoder does not look at the query and document separately.

  • It takes a single combined input string: [CLS] Query [SEP] Document Chunk [SEP].
  • Because it sees both together, it can perform “cross-attention” – literally weighing every word in the query against every word in the document at the same time.
  • It produces a single relevance score (usually a fractional number between 0 and 1). This is why it’s so accurate but also slow; you can’t pre-calculate these scores because they depend on the specific query being asked.

Reranking in application middleware

Reranking is almost always handled in the application layer or via a dedicated inference endpoint. Database stored procedures are great at maths (RRF), but they aren’t ideal for running heavy deep-learning models like the cross-encoder models typically used for reranking.

  • Your application middleware calls the database to get the top 50 “candidates” (via hybrid search), then sends those 50 raw text chunks to a reranking model.
  • The reranker returns the final “best” 5–10 chunks, which your application then feeds to the LLM.

Wrap-up

So we’ve examined in more detail how modern, production-grade RAG architectures use hybrid search and reranking to get the best results (and user experience):

  • Vector search engines need the data to be encoded into vectors using an embedding model. The search index is then built over those vectors.
  • Vector search results can be combined with keyword search results to deliver more accuracy. You’ll use an algorithm like RRF to calculate a combined result ranking. That’s called hybrid search.
  • You feed the results of the hybrid search into a reranking model in order to get the best results to the top of the result list, helping to make sure that the LLM responds based on the most relevant available information.

Hybrid search helps make sure that you don’t miss anything, and reranking helps to make sure the best stuff is at the very top.

The complete production RAG flow typically looks like this:

TaskLocationWhy?
Calculate embeddingsMiddleware / APIRequires a GPU heavy model to compute embeddings
Store embeddingsDatabaseEmbeddings need to be stored for later search  and retrieval
Vector/keyword searchesDatabaseNeeds direct access to the database indexes.
Hybrid searchDatabase stored procedureFaster to rank at the source than fetching two huge lists to the app.
RerankingMiddleware / APIRequires a GPU-heavy Cross-Encoder model.
LLM generationMiddleware / APIThe final step that uses the retrieved context.

Learn more about Canonical’s OpenSearch and PostgreSQL solutions, or get in touch.

Further reading

Explore our “Guide to RAG” to build and deploy a RAG workflow on public clouds with open source tools.