# Vector databases, chunking and hybrid search: where RAG storage leaks

> Chunking, vector databases, HNSW, hybrid search, metadata filters and ingestion in plain words, then how RAG storage leaks: missing permissions, open databases, deleted data.

- Published: 2026-11-23
- Topics: AI security, RAG, Vector databases
- Canonical page: https://thesecguy.com/notes/vector-databases-chunking-hybrid-search-security/
- Publisher: The Sec Guy (https://thesecguy.com)

**Short answer:** Before a RAG chatbot can search your documents, a pipeline cuts them into chunks, turns each chunk into a vector and files it in a vector database. That index is a second copy of your data, and it keeps the original permissions only if someone builds that in. In April 2025, UpGuard found 406 of 1,170 internet-facing Chroma databases exposing data. In a 2025 preprint, hidden text got past document loaders in 74.4% of 357 test scenarios. A 2026 preprint recovered deleted vectors from disk. Filter every search by the asking user's rights and protect the index like the documents it copies.

---

A RAG chatbot answers from documents it searched a moment ago. Our note on [how RAG search gets fooled](https://thesecguy.com/notes/rag-cosine-similarity-reranking-poisoning/) covers the search: embeddings, cosine similarity and rerankers. This one covers what happens earlier, when your files are copied into the thing that gets searched.

That copy is easy to forget. It holds the text of your documents in a second place, with its own access rules, its own network address and its own idea of what has been deleted.

## Chunking, in plain words

A long manual is too much to hand to a model for every question, so the pipeline cuts it into index cards. Each card holds a few paragraphs. When you ask something, the system pulls the few cards that match and the model reads only those. Why the model can't read everything every time is in our [context window note](https://thesecguy.com/notes/llm-context-window-explained/).

Scissors don't read. A cut can land between "Refunds are allowed within 30 days" and "except for sale items", and the two halves end up on different cards. To soften that, each card repeats the last lines of the card before it. The repeat is called overlap.

<figure class="fig">
<p class="fig-k">One rule, cut in the wrong place</p>
<div class="flow">
<div class="node"><b>The document says</b><span>Refunds are allowed within 30 days, except for sale items</span><div class="chips"><i class="chip">one rule</i></div></div>
<div class="node"><b>Chunk A</b><span>...Refunds are allowed within 30 days</span><div class="chips"><i class="chip">retrieved</i></div></div>
<div class="node"><b>Chunk B</b><span>except for sale items. Shipping fees are...</span><div class="chips"><i class="chip">not retrieved</i></div></div>
<div class="node"><b>With overlap</b><span>Chunk B starts by repeating the end of chunk A, so one chunk holds the whole rule</span><div class="chips"><i class="chip">repeat at the seam</i></div></div>
</div>
<figcaption>Our illustration. The refund rule is made up.</figcaption>
</figure>

## Chunking, technically

LangChain's [documentation](https://docs.langchain.com/oss/python/langchain/chunking) puts it in one line: "Chunking splits your source documents into smaller pieces before you embed and index them." Its example splitter aims for 1,000 characters per chunk with 200 repeated from the neighbor. It "splits on a descending list of separators (paragraphs, then sentences, then words)", so paragraph breaks are tried first.

On size, the same page says: "Chunk size trades precision against context, and there is no universal best value." Weaviate's [guide](https://weaviate.io/blog/chunking-strategies-for-rag) suggests starting with "a chunk size of 512 tokens and a chunk overlap of 50-100 tokens".

Overlap, in LangChain's words, exists "so that an idea split at a boundary still appears whole in at least one chunk". It does nothing for a qualifier that sits three pages from its rule. One consequence we'd point out ourselves: every chunk is stored and retrieved alone, so it travels without the header, the "DRAFT" stamp or the confidentiality banner that sat somewhere else in the file.

## The vector database and approximate search, in plain words

Every chunk gets an address on the map of meaning described in the RAG note. The vector database is the building that keeps all those addresses and answers one question: which stored addresses are nearest to this one?

Checking every address works for a small town. For a whole country it's too slow, so the database builds something like a road network: a few highways, regional roads below them, and local streets that reach every house. A search starts on the highway, then takes smaller roads. It usually ends at the closest house. Now and then it stops at the second closest, because no road led to the true one. That is the "approximate" in approximate nearest neighbor search.

<figure class="fig">
<p class="fig-k">How an HNSW search walks down to a neighbor</p>
<div class="flow">
<div class="node"><b>Top layer</b><span>Very few points, joined by long links. The search enters here</span><div class="chips"><i class="chip">highways</i></div></div>
<div class="node"><b>Middle layers</b><span>More points, shorter links. Each step moves closer to the question's vector</span><div class="chips"><i class="chip">regional roads</i></div></div>
<div class="node"><b>Bottom layer</b><span>Every stored vector, joined to its near neighbors</span><div class="chips"><i class="chip">local streets</i></div></div>
<div class="node"><b>Result</b><span>A short list of close vectors. Usually the closest ones, with no guarantee</span><div class="chips"><i class="chip">approximate</i></div></div>
</div>
<figcaption>Our illustration of the layered graph described by Malkov and Yashunin.</figcaption>
</figure>

## The vector database and approximate search, technically

With no index, EDB's [pgvector documentation](https://www.enterprisedb.com/docs/pg_extensions/pgvector/using/) says the database "performs exact nearest-neighbor search by scanning the entire table". That gets slow as the table grows, so "indexes trade a small amount of recall for significantly faster query times". Recall is the share of the true nearest neighbors that the index hands back.

The common index is HNSW, from a [2016 paper](https://arxiv.org/abs/1603.09320) by Yu. A. Malkov and D. A. Yashunin. It "builds a multi-layer structure consisting from hierarchical set of proximity graphs (layers)". Search starts in the upper layer and works down, which the authors say "allows a logarithmic complexity scaling". In plain terms, search time grows much more slowly than the collection does. Settings decide how hard the search looks. In pgvector the query-time one is `ef_search`, default 40, and "Increasing `ef_search` improves recall at the cost of query latency". Whatever the settings, the index ranks by distance and has no idea who is asking.

## Hybrid search, in plain words

Picture two clerks. The first understands what you mean: ask about "money back" and they bring cards about refunds. The second matches exact words: ask for part number KX-4410 and they bring every card containing that string. The first clerk is poor at part numbers. The second doesn't know that "money back" means "refund". Hybrid search asks both and merges their lists.

## Hybrid search, technically

The second clerk is usually BM25. Weaviate's [explainer](https://weaviate.io/blog/hybrid-search-explained) says it "builds on the keyword scoring method TF-IDF" and scores by "weighing the uniqueness of each keyword in the query relative to the collection of texts", so rare words count for more. The same article sums up the split: "dense vectors excel at understanding the context of the query, whereas sparse vectors excel at keyword matches".

Weaviate's [documentation](https://docs.weaviate.io/weaviate/concepts/search/hybrid-search) describes the merge: "A hybrid search runs both search types in parallel and combines their scores to produce a final ranking of results." A setting called alpha weights the two sides, and "`0.75` is the server default", which leans toward vectors. The default method, `relativeScoreFusion`, rescales each list's scores to a common range before adding them. The older `rankedFusion` uses only each result's position in its list.

Our own observation: hybrid search means a second index, and a keyword index holds the words of your documents as plain terms. Protect both the same way.

## Metadata filters and namespaces, in plain words

Each card carries labels: department, customer, date, who may read it. A filter is the instruction "search only cards labeled Finance". A namespace goes further. It is a separate drawer for each customer, and a search opens one drawer.

Both depend on the person at the counter. If the clerk opens whichever drawer the visitor names, the drawers protect nothing.

<figure class="fig">
<p class="fig-k">Three ways to keep customers apart in a vector database</p>
<div class="flow">
<div class="node"><b>One shared space, a label on every record</b><span>Every search must add "customer = X". One search without it reads everyone's data</span><div class="chips"><i class="chip">metadata filter</i></div></div>
<div class="node"><b>One namespace per customer</b><span>A search targets a single namespace. The application still has to name the right one</span><div class="chips"><i class="chip">namespace</i></div></div>
<div class="node"><b>One index or database per customer</b><span>Separate storage that can have its own credentials. More to run</span><div class="chips"><i class="chip">full separation</i></div></div>
</div>
<figcaption>Our summary. The first two options follow Pinecone's multitenancy guide.</figcaption>
</figure>

## Metadata filters and namespaces, technically

Pinecone's [guide](https://docs.pinecone.io/guides/index-data/implement-multitenancy) recommends a namespace per tenant (a tenant is one customer of a shared service), because "all upserts, searches, and other data read and write operations always target one namespace". Storing tenants apart, it says, "reduces the risk of application bugs that could search the wrong tenant's data". The alternative is a shared namespace with a tenant label on every record. Pinecone's first objection is cost, since there "Searches scan the entire namespace regardless of filters". Ours is that isolation then rests on the filter being right in every code path.

In both designs the application names the namespace or builds the filter. The tenant ID has to come from the signed-in session, never from the request.

Filters also collide with approximate search. The [pgvector README](https://github.com/pgvector/pgvector/) says that with approximate indexes, "filtering is applied after the index is scanned". The example given: "If a condition matches 10% of rows, with HNSW and the default hnsw.ef_search of 40, only 4 rows will match on average." pgvector's remedy is iterative index scans, which read more of the index. Removing the filter to get more results back is the wrong repair.

<figure class="fig">
<p class="fig-k">pgvector's own example: what a filter leaves of an approximate search</p>
<div class="hbars">
<div class="hbar"><em>Candidates the HNSW index returns (default ef_search)</em><div class="track"><i style="width:100%"></i></div><b>40</b></div>
<div class="hbar hot"><em>Left after a filter that matches 10% of rows, on average</em><div class="track"><i style="width:10%"></i></div><b>4</b></div>
</div>
<figcaption>Source: pgvector README, "Filtering".</figcaption>
</figure>

## The ingestion pipeline, in plain words

Think of a mail room. It connects to the shared drives, the wiki and the chat tool, opens every file, copies out the text, cuts it into cards and files them. It comes back on a schedule to pick up changes.

Two of its habits matter for security. It copies everything in a file, including text a person looking at the page would never see. And it files copies, so shredding the original does nothing to the card until the mail room is told.

## The ingestion pipeline, technically

LlamaIndex calls the first step a [data connector](https://developers.llamaindex.ai/python/framework/module_guides/loading/connector/), or Reader, which will "ingest data from different data sources and data formats into a simple `Document` representation". Its sample list includes Notion, Google Docs, Slack and Discord. Parsing, chunking, embedding and the write to the index follow.

Permissions travel separately, if they travel at all. Microsoft's [Azure AI Search documentation](https://learn.microsoft.com/en-us/azure/search/search-document-level-access-overview) is plain about the gap. For one of its sources, "ADLS user and group ACLs are indexed snapshots", and "Permission refresh doesn't provide immediate revocation or a corpus-wide freshness SLA." ADLS is Azure Data Lake Storage, and an ACL is the list of who may open a file. If your own code pushes documents in, "Custom push ingestion remains responsible for synchronizing its own metadata."

<figure class="fig">
<p class="fig-k">The storage half of RAG and where each problem lands</p>
<div class="flow">
<div class="node"><b>1. Connect</b><span>Readers pull files from drives, wikis and chat</span><div class="chips"><i class="chip">permissions left behind</i></div></div>
<div class="node"><b>2. Parse and chunk</b><span>Files become text, text becomes chunks</span><div class="chips"><i class="chip">hidden text</i><i class="chip">lost context</i></div></div>
<div class="node"><b>3. Embed and index</b><span>Vectors, a keyword index and labels are written</span><div class="chips"><i class="chip">stale copies</i><i class="chip">deleted vectors</i></div></div>
<div class="node"><b>4. The database</b><span>A server with an API and a network address</span><div class="chips"><i class="chip">open to the internet</i></div></div>
<div class="node"><b>5. Search</b><span>Nearest chunks, narrowed by filter or namespace</span><div class="chips"><i class="chip">no permission check</i><i class="chip">wrong tenant</i></div></div>
</div>
<figcaption>Our mapping of the weaknesses described below onto a typical ingestion pipeline.</figcaption>
</figure>

## Attack 1: ask the bot for what you can't open

This one needs no exploit. If the search doesn't check the asker's rights, any employee can ask about salaries and receive chunks of a file they could never open. OWASP's [LLM08:2025](https://genai.owasp.org/llmrisk/llm082025-vector-and-embedding-weaknesses/) entry starts there: "Inadequate or misaligned access controls can lead to unauthorized access to embeddings". Our [comparison of the 2026 list](https://thesecguy.com/notes/owasp-llm-top-10-2026-vs-2025/) shows where that entry moved.

The standard defense is to trim results by identity at query time. Microsoft's documentation says "Security filters are a technique for achieving document-level access control", with results "trimmed to exclude any matches that fail to include the user or group identity string". It also states the limit: "Application-managed string filtering also depends on the application's authentication and filter construction."

A related failure reached a shipped product. In February 2026, [The Register](https://www.theregister.com/2026/02/18/microsoft_copilot_data_loss_prevention/) and [BleepingComputer](https://www.bleepingcomputer.com/news/microsoft/microsoft-says-bug-causes-copilot-to-summarize-confidential-emails/) reported a Microsoft service notice, CW1226324, about Copilot Chat summarizing emails that carried a confidential label. The mail sat in the user's own Drafts and Sent Items folders. The Register quotes a Microsoft statement that the issue was "addressed" with a configuration update for enterprise customers, and that "This did not provide anyone access to information they weren't already authorized to see." BleepingComputer reported on 20 February that the fix was still reaching a small set of environments. So, by Microsoft's account, a policy label was skipped on users' own mail and nobody read a stranger's files. We saw the notice only through those two reports.

## Attack 2: read a neighbor's data through a shared index

OWASP's second scenario is the multi-tenant one: "different groups or classes of users share the same vector database", and "embeddings from one group might be inadvertently retrieved" for another group's query. The fix it gives: "A permission-aware vector database should be implemented to restrict access".

OWASP presents this as a scenario, and we did not find a public incident write-up for it that we could open. From the mechanics above, we'd look for it in two places: a tenant ID read from the request body, and a background job that searches with no filter at all.

## Attack 3: find the database on the open internet

A vector database is a server. In August 2024, Naphtali Deutsch of [Legit Security](https://www.legitsecurity.com/blog/the-risks-lurking-in-publicly-exposed-genai-development-services) searched for exposed ones. The report says: "Our investigation found around 30 servers with evidence of corporate or private data." Reading took no skill: "In all these cases, no vulnerabilities or tools were needed to read the data." The same interfaces allowed changes and deletes.

UpGuard ran a wider count. "When we surveyed the internet in April 2025, there were 1170 internet-accessible Chroma databases", [its report](https://www.upguard.com/blog/open-chroma-databases-ai-attack-surface) says, and "we found 406, or about one third, exposing some form of data". It quotes Chroma's security documentation: "By default, Chroma does not require authentication." UpGuard adds that many of the open instances looked like experiments holding little real data.

Then someone used the write access. In October 2026, UpGuard [reported](https://www.upguard.com/labs/research/poisoned-vector-jadepuffer-using-unauthenticated-chroma-databases-for-retrieval-extortion) that it had "identified 6 IP addresses hosting Chroma databases without authentication" that showed ransom activity under the name JADEPUFFER. The ransom note demanded "$2,500 USD in BTC". In one database the data was replaced with encrypted documents. In two, plain-text ransom notes were planted as documents "meant to poison RAG retrieval", so that a chatbot would fetch the note and show it to users. UpGuard calls it "the first documented AI-retrieval-stack extortion". The report doesn't say that anyone paid or that any chatbot displayed a note, and it allows that the JADEPUFFER name may have been used by a separate group.

## Attack 4: recover what was deleted

The first version is staleness. A file is deleted or locked down at the source, and its chunks stay searchable until the next sync notices. Microsoft's warning about no "immediate revocation" describes that window.

The second version sits inside the index. A June 2026 preprint from Trinity College, ["Ghost Vectors"](https://arxiv.org/abs/2606.18497), looked at three HNSW implementations (ChromaDB, FAISS and Weaviate). On a delete, it says, "the systems typically only mark the record as deleted". As a result, "deleted vectors remain physically recoverable by accessing the raw index files at the storage layer". Using an embedding inversion model on deleted vectors of 98 Wikipedia biographies, the authors could "recover 25.5% of exact person names and 46.4% of geographic locations".

The limits are real. For Weaviate the evidence was indirect: the authors could not pull vectors out of its file format and point to disk space that was not freed. The attacker needs read access to the storage directory, for example through a backup or a misconfigured bucket, and has to know the embedding model. The paper is not peer reviewed. How inversion works is covered in the [RAG note](https://thesecguy.com/notes/rag-cosine-similarity-reranking-poisoning/).

## Attack 5: hide text in a file the loader will read

A 2025 preprint by researchers mostly from the University of Padua, ["The Hidden Threat in Plain Text: Attacking RAG Data Loaders"](https://arxiv.org/abs/2507.05093v1), tested the mail room directly. They built "19 stealthy injection techniques" for DOCX, HTML and PDF files and ran them against "five popular data loaders": Docling, Haystack, LangChain, LlamaIndex and LLMSherpa. The result was "a 74.4% attack success rate across 357 scenarios". Success here means the manipulated text came out of the loader, before any chatbot answered anything. The techniques include zero-size fonts, transparent text, text outside the page bounds, metadata fields and zero-width characters.

They also tried full systems, among them NotebookLM and OpenAI Assistants, where results differed by system. The paper is marked "currently under submission", so it has not been peer reviewed.

OWASP's entry describes the same trick with a resume and asks for "text extraction tools that ignore formatting and detect hidden content". What hidden text does once the model reads it is in [Prompt injection: 6 real AI agent hijacks and the 5 fixes](https://thesecguy.com/notes/prompt-injection-6-real-ai-agent-hijacks/).

<figure class="fig">
<p class="fig-k">Three numbers from the research on RAG storage</p>
<div class="tiles">
<div class="tile hot"><b>406</b><span>of 1,170 internet-facing Chroma databases exposed some data</span><small>UpGuard scan, April 2025</small></div>
<div class="tile"><b>74.4%</b><span>success for hidden-text attacks across 357 loader scenarios</span><small>Castagnaro et al., preprint 2025</small></div>
<div class="tile"><b>25.5%</b><span>of person names recovered from deleted vectors</span><small>Wikipedia biographies, preprint 2026</small></div>
</div>
<figcaption>Sources: UpGuard 2025; Castagnaro et al. 2025; Chakraborttii et al. 2026. The two preprints are not peer reviewed.</figcaption>
</figure>

## What to check, with an example

Take a made-up company. Its support chatbot indexes product manuals, the internal wiki and the tickets of 300 customers. Every scenario below is illustrative.

1. **Does every search carry the asker's identity?** Without it, Attack 1 is one question away. Say a contractor asks the bot about a pending acquisition and gets a chunk of a board memo. That happens because the connector could read the whole wiki and nothing trims the results.
2. **Where does the tenant ID come from?** It should come from the session on the server. If the search API accepts `customer_id` in the request, a customer can change one digit and read another company's tickets.
3. **Can the database be reached from the internet, and does it ask for a login?** The scans above found the ones where the answers were yes and no. Here, a developer starts a test instance on a public cloud VM, loads real tickets to try a feature, and leaves it running.
4. **What happens to chunks when the source changes?** Deletes and permission changes have to reach the index. For example, HR removes a spreadsheet from the drive on Monday, and the bot quotes it on Thursday because the sync only adds and updates.
5. **What does the parser do with text nobody can see?** Strip or flag transparent text, zero-size fonts and metadata before chunking. Say a customer attaches a PDF with invisible instructions to a ticket, and the loader indexes them next to the visible text.
6. **Are the index and its backups protected like the documents?** That covers vectors, the keyword index and old snapshots. Picture source files that sit in an encrypted, access-logged store while nightly index backups go to a bucket half the engineering team can read.

---

**Sources** (all checked 23 November 2026)
- LangChain documentation, "Chunking": [docs.langchain.com](https://docs.langchain.com/oss/python/langchain/chunking)
- Plantinga, Slocum (Weaviate), "Chunking Strategies to Improve LLM RAG Pipeline Performance", 4 September 2025: [weaviate.io](https://weaviate.io/blog/chunking-strategies-for-rag)
- Malkov, Yashunin, "Efficient and robust approximate nearest neighbor search using Hierarchical Navigable Small World graphs", 2016: [arxiv.org/abs/1603.09320](https://arxiv.org/abs/1603.09320) <!-- style-ok: paper title -->
- EDB documentation, "Using pgvector": [enterprisedb.com](https://www.enterprisedb.com/docs/pg_extensions/pgvector/using/), and pgvector README, "Filtering": [github.com/pgvector/pgvector](https://github.com/pgvector/pgvector/)
- Shorten (Weaviate), "Hybrid Search Explained", 27 January 2025: [weaviate.io](https://weaviate.io/blog/hybrid-search-explained), and Weaviate documentation, "Hybrid search": [docs.weaviate.io](https://docs.weaviate.io/weaviate/concepts/search/hybrid-search)
- Pinecone documentation, "Implement multitenancy": [docs.pinecone.io](https://docs.pinecone.io/guides/index-data/implement-multitenancy)
- LlamaIndex documentation, "Data Connectors": [developers.llamaindex.ai](https://developers.llamaindex.ai/python/framework/module_guides/loading/connector/)
- Microsoft Learn, "Document-level access control in Foundry IQ (Azure AI Search)": [learn.microsoft.com](https://learn.microsoft.com/en-us/azure/search/search-document-level-access-overview)
- OWASP GenAI Security Project, "LLM08:2025 Vector and Embedding Weaknesses": [genai.owasp.org](https://genai.owasp.org/llmrisk/llm082025-vector-and-embedding-weaknesses/)
- The Register, "Copilot spills the beans, summarizing emails it's not supposed to read", 18 February 2026: [theregister.com](https://www.theregister.com/2026/02/18/microsoft_copilot_data_loss_prevention/), and BleepingComputer, "Microsoft says bug causes Copilot to summarize confidential emails", 18 February 2026, updated 20 February: [bleepingcomputer.com](https://www.bleepingcomputer.com/news/microsoft/microsoft-says-bug-causes-copilot-to-summarize-confidential-emails/) (both secondary, quoting Microsoft's notice CW1226324)
- Deutsch (Legit Security), "The Risks Lurking in Publicly Exposed GenAI Development Services", 22 August 2024: [legitsecurity.com](https://www.legitsecurity.com/blog/the-risks-lurking-in-publicly-exposed-genai-development-services)
- Pollock (UpGuard), "Open Chroma Databases: A New Attack Surface for AI Apps", updated 1 December 2025: [upguard.com](https://www.upguard.com/blog/open-chroma-databases-ai-attack-surface)
- Pollock (UpGuard), "Poisoned Vector: JADEPUFFER and Using Unauthenticated Chroma Databases for Retrieval Extortion", 13 October 2026: [upguard.com](https://www.upguard.com/labs/research/poisoned-vector-jadepuffer-using-unauthenticated-chroma-databases-for-retrieval-extortion)
- Chakraborttii, García Alvarado, Abdulofizova, Dwivedi (Trinity College), "Ghost Vectors: Soft-Deleted Embeddings Remain Reconstructible in HNSW Vector Databases", preprint, June 2026: [arxiv.org/abs/2606.18497](https://arxiv.org/abs/2606.18497)
- Castagnaro, Salviati, Conti, Pajola, Pizzi, "The Hidden Threat in Plain Text: Attacking RAG Data Loaders", preprint, July 2025: [arxiv.org/abs/2507.05093](https://arxiv.org/abs/2507.05093v1)
