The useful part, up front

What you’ll take away

  • Text is split into chunks that fit model token limits, then embedded by the same model for stored chunks and queries so that similarity search can return the closest chunks[2][3].
  • Cosine similarity compares vector direction after normalisation, while dot product also reflects magnitude, so the choice of distance changes what counts as similar[3].
  • Closeness in vector space is a useful retrieval signal, not a guarantee of identical meaning; word order, negation, and out-of-topic queries can produce misleading nearest neighbours[3].
  • Chunk size, overlap, and top-k have no universal optimum and must be tuned for the specific content, models, and task[2][3].
01

One bounded everyday example to carry through the whole explanation

Imagine a small, hypothetical set of household notes kept on a fridge door. One note says, "Buy oat milk for tea." A second says, "Oat milk is in the blue carton." A third, unrelated note says, "Water the basil on the windowsill." We will use only these three invented notes throughout, so every later step can be checked against the same tiny collection[3].

The question is simple to state and harder to answer: can a computer turn each note into numbers so that the two milk notes are treated as close, while the basil note is treated as farther away? The sources describe a retrieval system in which documents are split into chunks, each chunk is embedded, and a query is embedded by the same model so that a similarity search can return the closest stored chunks[3]. That is the mechanism we will follow, without pretending that closeness in numbers is the same as understanding in every sense.

A bounded example matters because it prevents vague claims. If the milk notes end up near each other, we can ask what part of the process made that happen: the splitting, the token limit, the embedding model, or the distance measure. If they do not, we can also ask which step failed. Keeping the example small and hypothetical makes the limits visible instead of hiding them behind a large, impressive-sounding dataset[2].

Cosine similarity compares direction. Cosine similarity compares vector direction after normalisation, ignoring length[3].
Cosine similarity compares vector direction after normalisation, ignoring length[3]. · Ameer Journal — original explanatory diagramOriginal editorial illustration; no third-party artwork reused.
02

Why long text is split into chunks before it can be embedded

A whole document is often too long to embed as one piece. Splitting it into smaller chunks helps each piece fit within the input limits of an embedding model and makes it possible to retrieve one relevant piece instead of an entire document[2]. In our fridge-door example the notes are already short, but the same idea applies: each note, or each part of a longer note, becomes a separate unit that can be stored and found on its own[3].

There are several ways to split text, and none is best for every dataset. One approach uses a fixed size, such as a set number of words or characters, sometimes with a small overlap between neighbouring chunks so that context is not cut too abruptly[2]. Another approach splits at natural boundaries such as sentences, paragraphs, or headings, which can preserve the structure of the original text[1]. A third approach tries to keep meaningful units together, so that a chunk represents one idea rather than an arbitrary slice[2].

For the milk notes, a sentence-based split would keep "Buy oat milk for tea" together as one chunk. A fixed-size split that cut in the middle of that sentence could separate "Buy oat" from "milk for tea," which would be unhelpful. This is why the sources warn that chunks that are too small can split sentences and lose meaning, while chunks that are too large can mix several ideas together[3]. The right balance depends on the content and on how the chunks will be used[2].

03

Tokens: the units a model actually counts

Models do not count words in the way people do. They count tokens, which are smaller pieces of text, and the number of tokens in a piece of text depends on the tokenizer being used[2]. A short note such as "Buy oat milk for tea" will contain only a handful of tokens, but a long document can contain thousands. That is why chunk size is often measured in tokens rather than only in characters or words[3].

Token counting also explains why two chunks with the same number of characters can have different token lengths. The Azure documentation notes that character counts do not align exactly with token definitions, and that the token length of a chunk varies with its contents[2]. In practical terms, a chunk that looks short on the page might still be too long for a model with a small input limit, or it might be much shorter than expected[2].

For our hypothetical notes, token limits are not a problem because the notes are tiny. The lesson is still useful: before embedding any text, it is worth checking how many tokens it contains and whether it fits the model being used[3]. The sources show token counting being used to inform chunk-size decisions, rather than guessing from character length alone[2].

Chunking strategies compared. Fixed-size, structure-based, and semantic chunking make different trade-offs[1][2].
Fixed-size, structure-based, and semantic chunking make different trade-offs[1][2]. · Ameer Journal — original explanatory diagramOriginal editorial illustration; no third-party artwork reused.
04

From a chunk of text to a fixed-length vector

An embedding model turns a chunk of text into a list of numbers called a vector. The list has a fixed length for a given model, even though the original text can be short or long[3]. One tutorial in the sources works with embeddings of 384 dimensions, meaning each chunk is represented by 384 numbers[3]. The exact number depends on the model, but the idea is the same: text in, fixed-length list of numbers out.

The same model must be used for the stored chunks and for the query. When a person asks a question, that question is embedded by the same model, and the system searches for stored vectors that are closest to the query vector[3]. In our example, the question "Where is the oat milk?" would be turned into a vector, and the system would compare it with the vectors for the milk notes and the basil note[3].

It is important not to overstate what the numbers mean. The sources say that embeddings represent a document's meaning for the purpose of retrieval, and that closeness in meaning should be reflected in closeness of the vectors[3]. That is a design goal, not a promise that every nuance of meaning is preserved. A vector is a compressed numeric summary, and compression always leaves something out[3].

05

Why words in similar contexts can end up close together

The basic intuition is that words and phrases that appear in similar contexts tend to receive similar vectors. If "oat milk" often appears near words about tea, cartons, and shopping, its vector will reflect those associations. Another phrase that appears in similar contexts, such as "soy milk" in a shopping list, may therefore lie nearby in the vector space[3]. Closeness is a record of shared context, not a dictionary definition.

In our hypothetical notes, "Buy oat milk for tea" and "Oat milk is in the blue carton" share the words "oat milk" and a shopping or kitchen context. If the embedding model captures that shared context, the two vectors should be closer to each other than either is to "Water the basil on the windowsill," which shares neither the key words nor the topic[3]. The sources describe exactly this expectation: as embeddings represent meaning, closeness in meaning should be reflected in closeness of the vectors[3].

This tendency has limits. Similar context does not always mean similar meaning, and the sources do not provide a universal test that guarantees the milk notes will be nearest neighbours for every model[3]. The outcome depends on the model, the chunking, and the distance measure. Treating closeness as a useful signal for retrieval is reasonable; treating it as proof of identical meaning is not[3].

06

Measuring closeness: cosine similarity and dot product

Once text has become vectors, the system needs a way to measure closeness. One common measure is cosine similarity, which compares the direction of two vectors rather than their length[3]. Imagine two arrows pointing in almost the same direction: their cosine similarity is high, even if one arrow is longer than the other. If the arrows point in different directions, the similarity is lower[3].

Cosine similarity requires the vectors to be normalised, meaning they are rescaled to a standard length before comparison[3]. The sources show this being set explicitly when cosine similarity is chosen, with embeddings normalised to unit length[3]. Without normalisation, a longer vector could appear more similar to many others simply because of its size, which is usually not what a search system wants[3].

A different measure, the dot product, takes vector length into account. The sources note that this can have the undesirable effect of making a longer vector seem more similar to everything else[3]. For our milk example, cosine similarity would focus on whether the query vector points in a similar direction to the milk-note vectors, rather than on which vector happens to be longest[3].

Query-time retrieval flow. A query is embedded by the same model and compared with stored vectors[3].
A query is embedded by the same model and compared with stored vectors[3]. · Ameer Journal — original explanatory diagramOriginal editorial illustration; no third-party artwork reused.
07

Storing vectors and searching them with a query

After chunks are embedded, their vectors are stored in a vector database together with the original text and any useful metadata, such as where the chunk came from[3]. When a query arrives, it is embedded by the same model and compared with the stored vectors. The system returns the closest chunks, often a small number set by a parameter called top-k[3]. In our example, a query about oat milk should return the milk notes before the basil note if the vectors are well behaved[3].

The number of results matters. Retrieving more chunks, a larger top-k, increases the chance that a relevant chunk is included, but it also brings in more noise[3]. Retrieving too much text can overwhelm the next stage of the system, which has to read the retrieved chunks and produce an answer[3]. The sources therefore treat top-k and chunk size as tuning choices that balance relevance against overload[3].

Metadata is also important. Keeping track of the source of each chunk makes it possible to show where a retrieved note came from and to filter results[3]. For the fridge-door example, metadata might record which note each chunk came from, so that the system can present the original wording rather than only a list of numbers[3].

08

A worked hypothetical example, step by step

Let us walk through the hypothetical example with explicit assumptions. Assume, purely for illustration, that each note is one chunk, that the embedding model accepts short inputs, and that cosine similarity with normalised vectors is used[3]. The three chunks are therefore the three notes themselves. Each is embedded into a fixed-length vector, and the three vectors are stored with their original text[3].

Now assume a query: "Where is the oat milk?" The query is embedded by the same model[3]. Under our hypothetical assumption that the model captures shared context, the query vector should point in a direction closer to the two milk-note vectors than to the basil-note vector. A similarity search with top-k set to two would then return the two milk notes[3]. This is a hypothetical outcome, not a measured result from any real model.

The example also shows what could go wrong. If the notes had been split badly, or if a different distance measure had been used, the ranking could change[2][3]. If the query were "What should I water?" the basil note should rank first instead. The same pipeline can therefore produce different rankings for different queries, which is exactly what a retrieval system is supposed to do[3].

When closeness misleads. Word order, negation, and topic shift can make nearest neighbours misleading[3].
Word order, negation, and topic shift can make nearest neighbours misleading[3]. · Ameer Journal — original explanatory diagramOriginal editorial illustration; no third-party artwork reused.
09

Where closeness breaks down: word order, negation, and a new topic

Closeness in vector space is not the same as sameness of meaning. Consider word order: "The cat sat on the mat" and "The mat sat on the cat" contain the same words but describe different scenes. Whether an embedding model distinguishes them depends on the model, and the sources do not guarantee that every model will[3]. A retrieval system might return both for a query about cats and mats, even though only one is correct[3].

Negation is a sharper problem. "Buy oat milk" and "Do not buy oat milk" share most of their words and topic, so their vectors may be close even though the required actions are opposite[3]. The sources describe embeddings as representing meaning for retrieval, but they do not show that a small word such as "not" will always move a vector far enough to change the ranking[3]. A system that relies only on closeness could therefore retrieve a note that says the opposite of what the user wants.

A new topic creates a different kind of problem. If a query introduces a topic that is not represented in the stored chunks, the closest vector may still be returned even though none of the chunks is truly relevant[3]. The system always returns the nearest neighbours, whether or not they are near in an absolute sense. For the fridge-door example, a query about car repairs would still return one of the three notes as the closest, even though none of them answers the question[3].

10

Choosing settings and a practical checklist

There is no single best chunk size, overlap, or top-k value for every dataset. The sources repeatedly emphasise that these choices depend on the content, the models being used, and the task[2][3]. A system that stores short notes needs different settings from one that stores long reports. The sensible approach is to start with a reasonable default, test it on representative examples, and adjust based on what the retrieval actually returns[2].

A useful comparison is between fixed-size chunking and structure-based chunking. Fixed-size chunking is simple and predictable, and it guarantees that chunks stay within a size limit[2]. Structure-based chunking respects paragraphs, sentences, or headings, which can preserve meaning better when the text has clear structure[1]. For the milk notes, structure-based chunking is natural because each note is a sentence. For a long document with headings, structure-based chunking may be preferable, while for unstructured text a fixed size may be simpler[1][2].

Here is a practical checklist for the hypothetical fridge-door system. First, confirm that each chunk fits the embedding model's token limit[2]. Second, use the same embedding model and normalisation for stored chunks and queries[3]. Third, choose cosine similarity deliberately and normalise vectors if that measure is used[3]. Fourth, set top-k small enough to avoid overwhelming the reader, but large enough to include relevant chunks[3]. Fifth, test with negation, word-order, and out-of-topic queries, and inspect the actual rankings rather than assuming closeness means correctness[3].

Should this chunk be embedded?. A decision check before embedding a chunk[2][3].
A decision check before embedding a chunk[2][3]. · Ameer Journal — original explanatory diagramOriginal editorial illustration; no third-party artwork reused.
Follow the evidence

Sources & further reading

Explore the references behind this guide. External pages may change after our review.

  1. Text splitter integrations - Docs by LangChain
    LangChain · Accessed 6 Nov 2026
  2. Chunk Documents - Azure AI Search | Microsoft Learn
    Microsoft · Accessed 6 Nov 2026
  3. Advanced RAG on Hugging Face documentation using LangChain · Hugging Face
    Hugging Face · Accessed 6 Nov 2026

Article updated 6 Nov 2026.

Found something we should revisit?

Good explanations get better with thoughtful feedback.

Suggest a correction