➕How to add new Embeddings?
Embeddings are involved when similar documents to the user query need to be produced. Various embeddings models are available, both closed source and open source. For Enterprise, we use embeddings supported by LlamaIndex. To add new embeddings, four important things need to be added:
Configurable parameters
Loading the base embedding model with the parameters it supports, such as model name, API key, and so on.
Embedding text to embeddings, to convert text to embeddings
Batching and aggregation supporting functions that are used to evaluate the embeddings.
Config parameters
Define the dataclass that takes the parameters required to load the model. If an API key needs to be set in an environment variable, it should be added in the __post_init__
function. Some parameters may have default values, while others may be left as undefined.
E.g., model_name can either be initialised as:
model_name: str
model_name: str = field(default='BAAI/bge-small-en-v1.5')
Note: load_from_kwargs
is a default static method, that is used in every Embedding model. This ensures that the user can enter any parameters that is supported by that embedding model.
Load Embedding Model
The load
function in Enterprise RAG utilizes LlamaIndex embeddings. It simply initializes the embedding model.
Embed Text
The embed_text
function is simply used to convert a normal string into embeddings.
Supporting batching and agg embedding functions
These supporting functions are necessary for batching queries during evaluation. As we evaluate the Embedding models to obtain hit rate
and mean reciprocal rank (MRR)
, we need to generate question and answer (Q&A) pairs. The get_agg_embedding_from_queries
function facilitates this process. To pass batches of queries to the embeddings, we utilize the get_text_embedding_batch
function.
Last updated