{"record":{"id":"bb9f5aeaad49a844","repo":"run-llama/llama_index","slug":"optimizer-returned-zero-sentences","errorCode":null,"errorMessage":"Optimizer returned zero sentences.","messagePattern":"Optimizer returned zero sentences\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"llama-index-core/llama_index/core/postprocessor/optimizer.py","lineNumber":138,"sourceCode":"\n            num_top_k = None\n            threshold = None\n            if self.percentile_cutoff is not None:\n                num_top_k = int(len(split_text) * self.percentile_cutoff)\n            if self.threshold_cutoff is not None:\n                threshold = self.threshold_cutoff\n\n            top_similarities, top_idxs = get_top_k_embeddings(\n                query_embedding=query_bundle.embedding,\n                embeddings=text_embeddings,\n                similarity_fn=self._embed_model.similarity,\n                similarity_top_k=num_top_k,\n                embedding_ids=list(range(len(text_embeddings))),\n                similarity_cutoff=threshold,\n            )\n\n            if len(top_idxs) == 0:\n                raise ValueError(\"Optimizer returned zero sentences.\")\n\n            rangeMin, rangeMax = 0, len(split_text)\n\n            if self.context_before is None:\n                self.context_before = 1\n            if self.context_after is None:\n                self.context_after = 1\n\n            top_sentences = [\n                \" \".join(\n                    split_text[\n                        max(idx - self.context_before, rangeMin) : min(\n                            idx + self.context_after + 1, rangeMax\n                        )\n                    ]\n                )\n                for idx in top_idxs\n            ]","sourceCodeStart":120,"sourceCodeEnd":156,"githubUrl":"https://github.com/run-llama/llama_index/blob/afd0fef371831f9bda13e5af7167cf4e981278ab/llama-index-core/llama_index/core/postprocessor/optimizer.py#L120-L156","documentation":"Error \"Optimizer returned zero sentences.\" thrown in run-llama/llama_index.","triggerScenarios":"Thrown at llama-index-core/llama_index/core/postprocessor/optimizer.py:138 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Lower the optimizer's cutoff/percentile threshold so some sentences survive.","Check that the input nodes contain text and the embedding model works."],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"afd0fef371831f9bda13e5af7167cf4e981278ab","analyzedAt":"2026-08-15T05:42:58.429Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}