Basic AI Concepts Related to Cybersecurity · Topic 3 of 4

Data Security for AI, RAG and Embeddings

Why data security matters for AI: cleansing, verification, lineage, provenance, integrity, balancing, data types, watermarking, RAG and vector storage.

  • 6 min
  • Includes a diagram
In a nutshell
  • Provenance is the origin and trust of data; lineage is its path and transformations.
  • Cleansing removes errors, verification confirms data is genuine, and integrity controls detect changes.
  • Augmentation adds samples; balancing fixes the class mix.

What it is

An artificial intelligence (AI) model learns its behaviour from data, so whoever controls the data controls the model. Bad, biased or tampered data produces a bad, biased or compromised model, even when the code is perfect.

Data security for AI therefore covers more than confidentiality. It also covers quality (is the data correct?), origin (where did it come from?) and integrity (has it changed?), for training data and for the documents a model reads at run time.

CollectCleansefix errorsVerifycheck it is genuineBalance and augmentTracklineage and provenanceTrain or index

How it works

Data processing steps

StepWhat it meansWhy it matters for security
Data cleansingRemoving duplicates, errors, corrupt records and irrelevant fieldsRemoves junk that skews results and can strip planted records
Data verificationChecking data is accurate, complete and from the expected sourceCatches tampered or fake data before training
Data lineageThe record of how data moved and was transformed through pipelinesLets you trace a bad model output back to the step that introduced it
Data provenanceThe origin and ownership history of the data: who created it, when and under what termsProves the data is genuine and licensed for use
Data integrityAssurance that data has not been altered without authorisationHashes, signatures and access controls detect poisoning
Data augmentationCreating extra training samples by transforming existing ones or generating synthetic onesImproves robustness, but synthetic data must also be checked
Data balancingAdjusting the mix of classes, for example by oversampling rare cases or undersampling common onesStops a model ignoring rare but important events such as fraud

Lineage and provenance are easy to confuse. Provenance answers "where did this come from and can I trust it?", while lineage answers "what happened to it on the way here?".

Why balancing matters

Security data is usually unbalanced. In a log set, malicious events may be a tiny fraction of the total.

A model trained on that set can score high accuracy by labelling everything benign, which is useless. Balancing, or weighting the rare class, forces the model to learn what an attack looks like.

Data types

TypeDescriptionExamples
StructuredFixed fields in rows and columnsDatabase tables, firewall logs in a fixed schema
Semi-structuredTagged or keyed data without a rigid table schemaJavaScript Object Notation (JSON), Extensible Markup Language (XML), syslog with key value pairs
UnstructuredNo predefined modelEmails, Portable Document Format (PDF) reports, images, audio, chat transcripts

Unstructured data is the hardest to secure. Sensitive details such as names or account numbers hide inside free text, so they must be found by scanning before the data is used for training or retrieval.

Watermarking

Watermarking embeds a hidden, detectable signal in content or a model. For AI it has two main uses: marking AI-generated output so it can later be recognised as synthetic, and marking data sets or models so theft or unlicensed use can be proven.

Watermarks help with provenance and deepfake detection. They are not perfect, because editing, cropping or re-encoding content can weaken some of them.

Retrieval-augmented generation (RAG)

RAG lets a large language model (LLM) answer from an organisation's own documents without retraining. Documents are split into chunks, each chunk is turned into an embedding, and the embeddings are kept in a vector store.

An embedding is a list of numbers that represents the meaning of a piece of text, so similar meanings sit close together. At question time the query is also embedded, the closest chunks are retrieved, and they are added to the prompt.

DocumentsChunkEmbedding modelVector storeSimilarity searchfor each queryPrompt with contextLLM answer

Securing RAG and vector storage

Securing RAG: classified documents are chunked and embedded into an encrypted vector store that keeps access labels with each chunk, and an authenticated user's query retrieves only the chunks that user may read before the LLM answers from that context.

  • Permission-aware retrieval: filter chunks by the user's own access rights, or the model will happily summarise documents the user could never open.
  • Ingestion checks: scan and approve documents before indexing, because a planted document can carry hidden instructions or false facts.
  • Protect the vector store: encrypt it and restrict access. Embeddings are derived from the source text and can leak information about it, so treat them as being as sensitive as the documents.
  • Keep provenance metadata: store the source and owner with each chunk so answers can cite and be traced.

A worked example

A help desk assistant answers staff questions from an internal wiki using RAG. A user asks about salary bands and receives figures from a human resources (HR) page they have no right to see.

The cause is that retrieval ignored document permissions. The fix is to store each chunk with its access labels, filter results by the asking user's identity before they reach the prompt, and remove HR pages from the general index.

How the exam asks about this

  • "A team must show auditors where each training record originated and under which licence. Which of the following should they maintain?" Data provenance records.
  • "A fraud model labels nearly every transaction as legitimate because fraud is rare in the training set. Which of the following would best address this?" Data balancing, such as oversampling the fraud class.
  • "A RAG chatbot reveals contents of restricted documents to unauthorised users. Which of the following is the best control?" Permission-aware retrieval that filters chunks by the user's access rights.

What to remember for the exam

  • Provenance is the origin and trust of data; lineage is its path and transformations.
  • Cleansing removes errors, verification confirms data is genuine, and integrity controls detect changes.
  • Augmentation adds samples; balancing fixes the class mix.
  • Structured data has fixed fields, semi-structured data has tags or keys, and unstructured data has neither.
  • RAG retrieves chunks by embedding similarity from a vector store and adds them to the prompt.
Watch out

A RAG system inherits the access level of its index, not of the user. If retrieval does not check the user's permissions, everyone can read everything the index holds.

Common mistakes

Treating embeddings as harmless numbers. Embeddings encode the meaning of the source text and can leak it. Protect the vector store like the original documents.

Using "lineage" when the question is about origin. A question about where data came from, who made it or whether it is authentic points to provenance.

Assuming RAG removes the need for data controls. RAG avoids retraining, but the retrieved documents still need classification, ingestion checks and access filtering.

Check yourself

  • What is an embedding?

    A list of numbers that represents the meaning of text or other content, so that items with similar meaning are close together.

  • Why is data balancing important for security models?

    Attacks are usually rare in training data, and without balancing a model can ignore them while still looking accurate.

  • What does watermarking add for AI-generated content?

    A hidden, detectable signal that helps show the content is synthetic and supports provenance and deepfake detection.

Topic 3 of 4 in Basic AI Concepts Related to Cybersecurity

Test yourself on Basic AI Concepts Related to Cybersecurity

The full CompTIA SecAI+ CY0-001 question bank has 654 questions, with timed practice exams and an explanation for every answer.

This study guide is independent and is not affiliated with, endorsed by, or sponsored by CompTIA. Vendor names, certification names and exam codes are trademarks of their respective owners and are used for identification only.