How to Build RAG Data Pipelines for Regulated Insurance
Standard retrieval steps often leak context or lose traceability in insurance settings. The right pipeline design adds checkpoints without killing latency. Readers get concrete decisions on storage, logging, and error paths they can apply to a claims workflow.
By Andriy Markiv, Goatechs LLC
A retrieval system I was asked to look at answered a question about a 2021 claim using the 2023 version of the policy. The terms had changed in between. The answer was fluent, well sourced in the sense that it cited a real document, and wrong.
Nobody had made a mistake, exactly. The policy had been chunked and embedded, the query matched, the similarity scores were high. The pipeline did what it was built to do. It just had no idea that a claim filed in 2021 can only be answered by the policy that was in force in 2021, because nothing in the retrieval path knew what time it was.
That is the shape of most trouble with RAG data pipelines for regulated insurance. Not hallucination. Retrieval that is technically correct and contextually wrong, with no record afterwards of how it happened.
The demo passes and the audit does not
A typical pipeline takes a query, embeds it, searches a vector store, pulls the top k chunks, and hands them to a model. The store might be Pinecone, Weaviate or pgvector. The embeddings might come from text-embedding-3 or a self hosted model like BGE. Chunks are usually 500 to 1000 tokens, split on paragraph boundaries or with a sliding window.
All of that is fine. It is also the part nobody asks about.
The first question from a compliance officer is never about embeddings. It is some version of: where did this answer come from, and how would you prove that to an examiner. And the honest answer, for most pipelines of this shape, is that you cannot. A similarity score is not provenance. You can show which chunk was returned. You usually cannot show which version of which document it came from, who was allowed to see it, or whether the same query would return the same thing today.
The information was there at ingestion. The pipeline threw it away before generation, because nothing in the default pattern has a reason to keep it.
What the default pipeline keeps, and what you need
It is worth being concrete about the gap, because it is smaller than it sounds. This is not an argument for a different architecture. It is an argument for writing down more at the moment of retrieval.
| What is being asked | A default pipeline stores | What answering actually takes |
|---|---|---|
| Which document answered this? | A document ID in the vector metadata | Document ID, version, and a content hash that proves the text has not changed since |
| Was this the right version? | Nothing | Effective and expiration dates on every chunk, filtered against the date of the claim rather than today |
| Was the user allowed to see it? | Nothing, access is checked at the application layer if at all | The access decision itself, per document, recorded at retrieval time |
| Would it answer the same way now? | Nothing | Embedding model version, filters applied, and the top k with scores |
| What did the examiner ask about? | Application logs, maybe | The query, the user, and the timestamp, in one record joined to the rest |
Read the right hand column again and notice what is not in it. No new vector store, no reranker, no fine tuning. It is all metadata and logging, which is the least interesting work in the system and the only work that decides whether it can go to production in a regulated line of business.
Treat retrieval as a transaction, not a search
The reframe that makes the rest fall into place: a retrieval in this setting is closer to a database transaction than to a search box. It has a caller, a time, an authorization decision and a result set, and all four need to survive.
In practice the order matters. You check the user's access policy first, which in insurance is usually role based with segmentation by line of business, state or customer segment. Chunks from policies the user cannot see are never retrieved, rather than retrieved and filtered afterwards. Then you run the search, and you log what went in and what came out.
{
"retrieval_id": "ret_20240315_a7b3c",
"timestamp": "2024-03-15T14:32:18Z",
"user_id": "claims_examiner_47",
"query": "What is the deductible for wind damage on policy P-2021-8834?",
"embedding_model": "text-embedding-3-small",
"vector_store": "pgvector_claims_prod",
"filters": {"effective_date_lte": "2021-06-30", "line_of_business": "homeowners"},
"results": [
{"doc_id": "policy_P-2021-8834_v3", "chunk_id": 12, "score": 0.87, "doc_hash": "sha256:a3f2..."},
{"doc_id": "policy_P-2021-8834_v3", "chunk_id": 13, "score": 0.82, "doc_hash": "sha256:a3f2..."}
],
"access_granted": true
}The filters line is the one that would have caught the 2021 claim. The effective date is bound to the claim, not to the clock.
Six months later, that record answers the examiner's question directly. You can verify the hash still matches the stored document, show the access decision, and replay the retrieval against the same model version to confirm you get the same chunks. That is the whole difference between a demo and a system somebody is willing to sign off on.
Where this gets expensive, honestly
Logging every retrieval produces a great deal of data, and this is the part that usually gets waved through in design and then bites in month three.
A busy claims operation runs thousands of retrievals a day, each one carrying a query, a result set and a decision. Keep the query embedding in the log, as the example above does, and each record is suddenly kilobytes rather than bytes. Multiply that by a retention period tied to the claims retention rules, which in many states runs to seven years or more, and the audit log becomes a larger storage problem than the vector store it was built to explain.
There is no clever way out of that. There are only decisions, made early:
- Separate the log from the serving path. A retrieval log in its own table or a time series store, indexed on user, timestamp and document, keeps audit queries from competing with live retrieval.
- Decide what the embedding is worth. Storing the query vector makes exact replay possible. Storing a hash of it makes verification possible at a fraction of the size. Both are defensible; drifting into one by accident is not.
- Tier the retention. Full records hot for the period when disputes actually arise, then compacted to the fields an examiner asks for. The compaction rule is itself something you will be asked to explain, so write it down before you need it.
None of this is hard. It is just much cheaper to decide at design time than to retrofit onto eighteen months of logs you already have.
Access control is a question about time
The subtler problem is that access in insurance is rarely a static fact about a user and a document.
A claims examiner may be allowed to read a policy while a claim is open and not after it closes. An underwriter may see risk data for a renewal they are working and not for a competitor's book. The decision depends on the role, the document, the state of the matter and the reason for asking, and at least two of those change over the life of a claim.
Most RAG systems do not model this at all. They assume that a document in the vector store is available to anyone who can query the store, which is exactly the assumption that does not hold here. The practical consequence is that you cannot lean on the vector store's own metadata filtering alone, because it answers "does this chunk match the filter" and not "is this person entitled to this chunk right now". You need an authorization layer that evaluates the policy per document, before the chunks reach the model, and that records what it decided.
It is more moving parts than a tutorial pipeline. It is also the thing that makes the difference between a system that passes an internal review and one that quietly cannot.
What I would build first
If you are starting this work now, the order that has served me best is unglamorous. Put the retrieval log in before anything else, even if the first version writes to a single table and nobody reads it, because retrofitting provenance is far harder than capturing it. Add effective and expiration dates to chunk metadata at ingestion, and make the date filter mandatory rather than optional in the query path, so a missing date fails loudly instead of silently returning today's version. Then build the authorization layer, and only then spend time on retrieval quality.
That ordering feels backwards to most engineering teams, because retrieval quality is the interesting problem and logging is not. But quality improvements are easy to add to a system that records what it did, and nearly impossible to defend in a system that does not. This is the sort of sequencing question that comes up in most of the architecture work we do, and it is usually worth more than the model choice.
Frequently asked questions
Can I add auditability to a RAG pipeline that is already in production?
Yes, though it is more work than building it in. The retrieval log can be added without touching the vector store, since it records what the application asked for and received. The harder retrofit is chunk level metadata like effective dates, which usually means re-ingesting the corpus. Teams often run both pipelines in parallel for a period rather than cutting over.
Does logging the query embedding matter, or is the text enough?
It depends on what you need to prove. Logging the query text and the model version lets you re-run the retrieval and show you get the same result, which satisfies most internal reviews. Logging the embedding itself lets you prove the exact vector used, which matters more if the embedding model has been updated since. The embedding is significantly larger, so the choice is a storage decision as much as a compliance one.
Is pgvector enough, or do I need a dedicated vector database?
For this class of problem pgvector is often the better choice, precisely because the retrieval log and the vectors live in the same database and can be written in one transaction. A managed vector store means the audit record and the retrieval happen in different systems, and you have to reason about what happens when one write succeeds and the other does not. Scale eventually argues the other way, but it argues later than most teams expect.
How does this change under HIPAA rather than insurance regulation?
The structure is the same and the emphasis moves. Access decisions and minimum necessary access carry more weight, and the audit log needs to show not just that access was granted but why it was appropriate. The retention picture also changes. The engineering is largely portable between the two, which is one reason this pattern is worth building properly once.
If you are in the middle of this
Most of the teams I talk to are not stuck on the model. They are stuck on how to make a retrieval step explainable to somebody whose job is to doubt it. If that is where you are, I am happy to look at what you have and say where the provenance is leaking. You can see the kind of systems we build, or just get in touch and describe the problem.