{"record":{"id":"53e090daa9df9705","repo":"mem0ai/mem0","slug":"together-embed-batch-returned-len-embeddings","errorCode":null,"errorMessage":"Together embed_batch() returned {len(embeddings)} embeddings for {len(texts)} texts using model '{self.config.model}'","messagePattern":"Together embed_batch\\(\\) returned (.+?) embeddings for (.+?) texts using model '(.+?)'","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"mem0/embeddings/together.py","lineNumber":39,"sourceCode":"        Get the embedding for the given text using OpenAI.\n\n        Args:\n            text (str): The text to embed.\n            memory_action (optional): The type of embedding to use. Must be one of \"add\", \"search\", or \"update\". Defaults to None.\n        Returns:\n            list: The embedding vector.\n        \"\"\"\n\n        return self.client.embeddings.create(model=self.config.model, input=text).data[0].embedding\n\n    def embed_batch(self, texts, memory_action=\"add\"):\n        if not texts:\n            return []\n        response = self.client.embeddings.create(model=self.config.model, input=texts)\n        sorted_data = sorted(response.data, key=lambda x: x.index)\n        embeddings = [item.embedding for item in sorted_data]\n        if len(embeddings) != len(texts):\n            raise ValueError(\n                f\"Together embed_batch() returned {len(embeddings)} embeddings for {len(texts)} texts\"\n                f\" using model '{self.config.model}'\"\n            )\n        return embeddings\n","sourceCodeStart":21,"sourceCodeEnd":44,"githubUrl":"https://github.com/mem0ai/mem0/blob/001c235229be8795e3834520467bd0d661ed8f34/mem0/embeddings/together.py#L21-L44","documentation":"Raised by TogetherEmbedding.embed_batch when the Together AI embeddings endpoint returns a different number of vectors than input texts. After sorting response.data by index, the count check fails if Together dropped, merged, or truncated inputs — most often from batch-size limits on their embeddings API.","triggerScenarios":"Calling embed_batch with more texts than Together's per-request input cap for the given embedding model; Together API behavior differences across model versions (e.g. model.json files with different batch limits); empty strings in the batch.","commonSituations":"Bulk ingestion via Memory.add on the Together provider; switching embedding models on Together without re-checking limits; proxy/gateway between client and Together modifying the payload.","solutions":["Chunk texts to smaller batches (e.g. 32-128 per call) matching Together's documented batch limit for your model","Remove empty/whitespace texts before the call","Verify with a direct curl to api.together.xyz that N inputs return N embeddings for your model","Retry the failing chunk — transient server-side truncation is possible"],"exampleFix":"// before\nembs = embedder.embed_batch(texts)  # full list at once\n\n# after\nembs = []\nfor i in range(0, len(texts), 64):\n    embs.extend(embedder.embed_batch(texts[i:i+64]))","handlingStrategy":"retry","validationCode":"# keep batches within Together's per-request input cap\ntogether_batches = [texts[i:i+64] for i in range(0, len(texts), 64)]","typeGuard":null,"tryCatchPattern":"try:\n    vecs = embedder.embed_batch(batch)\nexcept ValueError as e:\n    if \"embeddings for\" in str(e) and len(batch) > 1:\n        mid = len(batch) // 2\n        vecs = embedder.embed_batch(batch[:mid]) + embedder.embed_batch(batch[mid:])\n    else:\n        raise","preventionTips":["Check Together docs for the embedding model's batch limit and stay under it","Strip empty strings from batches","Retry chunks idempotently on mismatch"],"tags":["python","together","embeddings","batching","api","mem0"],"backgroundTag":null,"analyzedSha":"001c235229be8795e3834520467bd0d661ed8f34","analyzedAt":"2026-08-15T01:55:42.685Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}