Home / Function/ _get_batches() — langchain Function Reference

_get_batches() — langchain Function Reference

Architecture documentation for the _get_batches() function in embeddings.py from the langchain codebase.

Entity Profile

Dependency Diagram

graph TD
  1ebd0b7d_e260_a53f_7605_d0c94c73ee54["_get_batches()"]
  8ffbd15a_923a_c258_fc8b_25df9b4cba69["MistralAIEmbeddings"]
  1ebd0b7d_e260_a53f_7605_d0c94c73ee54 -->|defined in| 8ffbd15a_923a_c258_fc8b_25df9b4cba69
  899cf409_68f4_e6ef_1223_d9393754b32d["embed_documents()"]
  899cf409_68f4_e6ef_1223_d9393754b32d -->|calls| 1ebd0b7d_e260_a53f_7605_d0c94c73ee54
  0451d400_70ed_ded5_006c_e334458a80ae["aembed_documents()"]
  0451d400_70ed_ded5_006c_e334458a80ae -->|calls| 1ebd0b7d_e260_a53f_7605_d0c94c73ee54
  c53ab1d5_62e8_23e4_ced5_b33c9f469df4["encode_batch()"]
  1ebd0b7d_e260_a53f_7605_d0c94c73ee54 -->|calls| c53ab1d5_62e8_23e4_ced5_b33c9f469df4
  style 1ebd0b7d_e260_a53f_7605_d0c94c73ee54 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

libs/partners/mistralai/langchain_mistralai/embeddings.py lines 200–221

    def _get_batches(self, texts: list[str]) -> Iterable[list[str]]:
        """Split list of texts into batches of less than 16k tokens for Mistral API."""
        batch: list[str] = []
        batch_tokens = 0

        text_token_lengths = [
            len(encoded) for encoded in self.tokenizer.encode_batch(texts)
        ]

        for text, text_tokens in zip(texts, text_token_lengths, strict=False):
            if batch_tokens + text_tokens > MAX_TOKENS:
                if len(batch) > 0:
                    # edge case where first batch exceeds max tokens
                    # should not yield an empty batch.
                    yield batch
                batch = [text]
                batch_tokens = text_tokens
            else:
                batch.append(text)
                batch_tokens += text_tokens
        if batch:
            yield batch

Domain

Subdomains

Frequently Asked Questions

What does _get_batches() do?
_get_batches() is a function in the langchain codebase, defined in libs/partners/mistralai/langchain_mistralai/embeddings.py.
Where is _get_batches() defined?
_get_batches() is defined in libs/partners/mistralai/langchain_mistralai/embeddings.py at line 200.
What does _get_batches() call?
_get_batches() calls 1 function(s): encode_batch.
What calls _get_batches()?
_get_batches() is called by 2 function(s): aembed_documents, embed_documents.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free