← All Insights

Clean Data Before Embeddings: A Practical Lesson from an AI Search Pipeline

When an AI search application produces an embedding, the model does not see the database field, the user interface, or what the text was intended to look like. It sees the text that the data pipeline actually sends it.

CBITS

That makes source-data quality an important part of vector search.

While maintaining an Azure AI Search application, we identified carriage-return and line-feed characters embedded in several textual fields used by the search pipeline. The visible content was still recognizable, but the underlying strings contained formatting that should have been normalized before being processed.

Rather than treating this as a handful of bad records, we approached it as a data-pipeline problem: determine exactly where the formatting occurred, clean the source representation consistently, regenerate the affected embeddings, update the index, and verify the result.

Hidden Formatting Is Still Data

Structured databases often contain text collected from multiple sources or entered over long periods of time.

A description might look perfectly normal when rendered in an application while containing characters such as carriage returns and line feeds underneath:

CR — carriage return LF — line feed

These characters are not inherently incorrect. Paragraphs and line breaks are legitimate parts of text.

The question is whether they carry useful meaning in a particular field.

If a field is expected to contain continuous descriptive text, inconsistent line-ending characters may simply be artifacts of how information was entered, imported, copied, or stored. Once that text becomes input to another processing system, those artifacts travel with it.

That becomes especially relevant when the next system is generating embeddings.

Diagnose the Dataset Before Changing It

Our first step was not to strip every line break from every text field.

It was to measure the problem.

We examined the fields participating in the search data and identified which records contained carriage-return or line-feed characters. The analysis covered multiple descriptive fields rather than assuming the issue existed in only one column.

That produced a record-level view of the problem: which entries were affected and which specific fields contained the formatting.

This approach matters because broad cleanup operations can be risky. Some formatting may be intentional, and different fields can have different requirements.

A useful data-cleaning workflow starts with:

Detect → quantify → understand → normalize

rather than:

Find something unusual → modify everything

Once we understood where the characters were appearing, we could make a targeted correction.

Normalize Before Generating Embeddings

Embeddings turn textual input into numerical vector representations that can be compared during semantic retrieval.

That makes preprocessing part of the retrieval architecture.

If two pieces of otherwise equivalent text are represented differently because one contains inconsistent whitespace or formatting artifacts, we are asking the embedding stage to account for variation that provides no useful search information.

Normalization creates a more consistent input.

The important point is not that every newline must always be removed. There is no universal cleanup rule for every embedding application.

Instead, preprocessing should reflect the semantics of the source field.

For this dataset, the affected fields contained textual information where the unwanted CR/LF formatting did not need to be preserved. Cleaning those values before embedding generation gave the downstream process a more consistent representation of the source content.

Correcting the Text Was Only Half the Job

Once embeddings have been generated, fixing the original text does not automatically fix the search index.

The vectors already stored in Azure AI Search represent the text that existed when those embeddings were created.

That meant the remediation sequence needed to continue downstream:

  • Normalize the affected source text.
  • Rerun the embedding process.
  • Upload the regenerated data and vectors to the search index.
  • Verify that the updated index contains the corrected information.

This is a useful characteristic to remember about AI data pipelines.

Derived data has lineage.

An embedding is derived from source text. If the source changes in a meaningful way, the derived representation may need to change as well.

The same principle applies beyond embeddings. Summaries, classifications, extracted entities, cached transformations, and other AI-generated artifacts can all become stale when their source information changes.

Verification Needs to Happen at More Than One Layer

After correcting the data, we did not consider the work complete simply because the cleanup script finished successfully.

We reran the embedding workflow, uploaded the resulting records to Azure AI Search, and checked the indexed data to confirm the update had actually made it through the pipeline.

That distinction becomes increasingly important as systems gain more processing stages.

Consider the chain involved:

Source data → normalization → embedding generation → index upload → searchable document

A successful first step tells us very little about the final one.

For production systems, it is useful to think about validation at each boundary. Did the source text get normalized? Did embedding generation complete? Did the index accept the updated records? Does the indexed representation now contain what we expect?

The farther an application moves from a simple database read, the more important that end-to-end thinking becomes.

Data Quality Is Part of AI Quality

Discussions about AI search quality tend to concentrate on models.

Which embedding model should we use? How large should the chunks be? Which vector-search configuration performs best? How should results be ranked?

Those are worthwhile questions.

But an excellent model cannot correct every problem created before the model receives its input.

A production retrieval system depends on several layers working together:

  • appropriate source data,
  • consistent text preprocessing,
  • correct embedding generation,
  • valid vector configuration,
  • reliable indexing, and
  • useful retrieval and ranking.

Improving any one of those layers can improve the finished system. Neglecting one can also undermine work done elsewhere.

This is why we increasingly treat preprocessing and data validation as first-class parts of AI application development rather than as preliminary cleanup.

What We Learned

The main lesson was straightforward: inspect what the model actually receives, not just what users see on screen.

Text that looks clean when rendered can have a different underlying representation. Data accumulated from different workflows can contain inconsistencies that were harmless in its original application but become important when that information is reused for AI processing.

We also reinforced a second engineering principle: when source data changes, trace its downstream dependencies.

In this case, cleaning the database without regenerating the embeddings would have left the search system using representations derived from the old text. Updating the entire path kept the source information, generated vectors, and Azure AI Search index aligned.

Neither step required a dramatic change in architecture. They required careful attention to the boundaries between systems.

That is often where production AI quality is won or lost.

Next Steps

Before building embeddings from an existing business dataset, it is worth profiling the source fields first.

Look for inconsistent whitespace, unexpected control characters, null or empty values, duplicated information, formatting inherited from other systems, and other artifacts that may not have mattered when the data was originally collected.

Then decide deliberately what should be preserved.

AI preprocessing should not mean indiscriminately stripping information from a dataset. It should mean creating a consistent representation while retaining the information that carries meaning.

For organizations developing search and AI applications, that work may be less visible than the model itself. It is also one of the foundations that makes the model useful.