Understand the Stages of Data Transformations
Your input data may travel through different stages before turning into a vector.
Depending on the size of your input data, which can range from small strings to very large documents, the data passes through a pipeline of optional transformation stages from Plain Text to Chunks to Tokens to Vectors, with Vector Index as the endpoint.
Prepare: Plain Text and Chunks
This stage prepares your unstructured data to ensure that it is in a format that can be processed by vector embedding models.
To prepare large unstructured textual data (for example, a PDF or Word document), you may first transform the document into plain text and then pass the resulting document through Chunker. The chunker then splits the plain text document into multiple appropriate-sized segments through a splitting process known as Chunking. A single document may be split into many chunks, each transformed into a vector. A chunk can be a set of words (to capture specific words or word pieces), sentences (to capture a specific context), or paragraphs (to capture broader themes).
Later, you will learn about several chunking parameters and techniques that help you define your own chunking specifications and strategies, so that you can generate relevant and meaningful chunks according to your use case.
Splitting your data into chunks is not needed for small documents, phrases, text strings, or short summaries. Embedding models can directly process such content into a vector representation. This is explained in the following section.
Embed: Tokens and Vectors
You now pass the text or extracted chunks as input through a declared vector embedding model for generating vector embeddings on each text string or chunk. Embeddings are vector representations that capture the semantic meaning or context of your data. A vector embedding model creates these embeddings by assigning numerical values to each element of your data, that is, to each word, sentence, or paragraph.
The chunks are first passed through Tokenizer associated with your embedding model. The tokenizer further splits the chunks into individual words or word pieces known as tokens. An embedding model then embeds each token into a vector representation.
Tokenizers used by embedding models usually have limits on the size of the input text (number of tokens) they can deal with, so it is important that you chunk your data beforehand into appropriate-sized segments to avoid loss of text when generating embeddings. If the number of tokens are larger than the maximum input limit imposed by the model, then some tokens get truncated into a defined input length. Note that chunking is not needed if your text meets this maximum input limit.
The chunker must select a text size that approximates the maximum input limit of your model. The actual number of tokens depends on the specified tokenizer for an embedding model, which typically uses a vocabulary list of words, numbers, punctuations, and pieces of tokens. A vocabulary contains a set of tokens that are collected during a statistical training process. Each tokenizer uses a different vocabulary format to process text into tokens.
For example, the BERT multilingual model uses Word-Piece encoding or the GPT model uses Byte-Pair encoding.
The BERT model may tokenize the following sentence (containing four words):
Embedding usecase for chunking
into the following eight tokens and also include ##
(number signs) to indicate non-initial pieces of words:
Em ##bedd ##ing use ##case for chunk ##ing
Vocabulary files are included as part of a model's distribution. You can supply a vocabulary file (recognized by your model's tokenizer) to the chunker beforehand, so that it can correctly estimate the token count of your input data at the time of chunking.
Populate and Query: Vector Indexes
Finally, you store the extracted vectors in a vector index to implement combined similarity and relational searches on those vectors.
Instead of creating a vector index alone, you can also choose to create a hybrid vector index, which is a combination of both vector index and Oracle Text search index. This lets you implement hybrid searches to retrieve more relevant search results by performing both vector-based similarity searches and text-based keyword searches on the same data, simultaneously.
Parent topic: About Vector Generation