async def aget_text_embedding_batch(
        self, texts: List[str], show_progress: bool = False
    ) -> List[Embedding]:
        """Asynchronously get a list of text embeddings, with batching."""
        num_workers = self.num_workers

        model_dict = self.to_dict()
        model_dict.pop("api_key", None)

        cur_batch: List[str] = []
        pre_recorded_embs: List[Embedding] = []
        non_cached_txts: List[str] = []
        callback_payloads: List[Tuple[str, List[str]]] = []
        result_embeddings: List[Embedding] = []
        embeddings_coroutines: List[Coroutine] = []
        for idx, text in enumerate(texts):
            cur_batch.append(text)
            if idx == len(texts) - 1 or len(cur_batch) == self.embed_batch_size:
                # flush
                dispatcher.event(
                    EmbeddingStartEvent(
                        model_dict=model_dict,
                    )
                )
                event_id = self.callback_manager.on_event_start(
                    CBEventType.EMBEDDING,
                    payload={EventPayload.SERIALIZED: self.to_dict()},
                )
                callback_payloads.append((event_id, cur_batch))
                if not self.embeddings_cache:
                    embeddings_coroutines.append(self._aget_text_embeddings(cur_batch))
                elif self.embeddings_cache is not None:
                    for txt in cur_batch:
                        cached_emb = self.embeddings_cache.get(
                            key=txt, collection="embeddings"
                        )
                        if cached_emb is not None:
                            cached_key = next(iter(cached_emb.keys()))
                            pre_recorded_embs.append(cached_emb[cached_key])
                        else:
                            embeddings_coroutines.append(
                                self._aget_text_embeddings([txt])
                            )
                            non_cached_txts.append(txt)

                cur_batch = []

        # flatten the results of asyncio.gather, which is a list of embeddings lists
        nested_embeddings = []

        if len(embeddings_coroutines) > 0:
            if num_workers and num_workers > 1:
                nested_embeddings = await run_jobs(
                    embeddings_coroutines,
                    show_progress=show_progress,
                    workers=self.num_workers,
                    desc="Generating embeddings",
                )
            else:
                if show_progress:
                    try:
                        from tqdm.asyncio import tqdm_asyncio

                        nested_embeddings = await tqdm_asyncio.gather(
                            *embeddings_coroutines,
                            total=len(embeddings_coroutines),
                            desc="Generating embeddings",
                        )
                    except ImportError:
                        nested_embeddings = await asyncio.gather(*embeddings_coroutines)
                else:
                    nested_embeddings = await asyncio.gather(*embeddings_coroutines)

        result_embeddings = [
            embedding for embeddings in nested_embeddings for embedding in embeddings
        ]
        if self.embeddings_cache is not None:
            if len(result_embeddings) > 0:
                for j in range(len(result_embeddings)):
                    self.embeddings_cache.put(
                        key=non_cached_txts[j],
                        val={str(uuid.uuid4()): result_embeddings[j]},
                        collection="embeddings",
                    )
                result_embeddings += pre_recorded_embs
            else:
                result_embeddings += pre_recorded_embs

        for (event_id, text_batch), embeddings in zip(
            callback_payloads, nested_embeddings
        ):
            dispatcher.event(
                EmbeddingEndEvent(
                    chunks=text_batch,
                    embeddings=embeddings,
                )
            )
            self.callback_manager.on_event_end(
                CBEventType.EMBEDDING,
                payload={
                    EventPayload.CHUNKS: text_batch,
                    EventPayload.EMBEDDINGS: embeddings,
                },
                event_id=event_id,
            )

        return result_embeddings
Asynchronously get a list of text embeddings, with batching.
llama-index-core/llama_index/core/base/embeddings/base.py