{"record":{"id":"658be9cd70483fe8","repo":"apache/beam","slug":"item-embeddable-item-id-missing-both-text-content-and-sparse","errorCode":null,"errorMessage":"Item {embeddable_item.id} missing both text content and sparse embedding required for keyword search","messagePattern":"Item (.+?) missing both text content and sparse embedding required for keyword search","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"sdks/python/apache_beam/ml/rag/enrichment/milvus_search.py","lineNumber":498,"sourceCode":"        param=self.search_strategy.keyword.search_params,\n        limit=self.search_strategy.keyword.limit,\n        expr=self.search_strategy.keyword.filter)\n\n    reqs = [vector_search_req, keyword_search_req]\n    return reqs\n\n  def _get_vector_search_data(self, embeddable_item: EmbeddableItem):\n    if not embeddable_item.dense_embedding:\n      raise ValueError(\n          f\"Item {embeddable_item.id} missing dense embedding required for\"\n          \" vector search\")\n    return embeddable_item.dense_embedding\n\n  def _get_keyword_search_data(self, embeddable_item: EmbeddableItem):\n    has_no_text = not embeddable_item.content.text\n    has_no_sparse = not embeddable_item.sparse_embedding\n    if has_no_text and has_no_sparse:\n      raise ValueError(\n          f\"Item {embeddable_item.id} missing both text content and sparse \"\n          \"embedding required for keyword search\")\n    sparse_embedding = MilvusHelpers.sparse_embedding(\n        embeddable_item.sparse_embedding)\n    return embeddable_item.content.text or sparse_embedding\n\n  def _get_call_response(\n      self,\n      embeddable_items: list[EmbeddableItem],\n      search_result: SearchResult[Hits]):\n    response = []\n    for i in range(len(embeddable_items)):\n      embeddable_item = embeddable_items[i]\n      hits: Hits = search_result[i]\n      result = MilvusSearchResult()\n      for j in range(len(hits)):\n        hit: Hit = hits[j]\n        normalized_fields = self._normalize_milvus_fields(hit.fields)","sourceCodeStart":480,"sourceCodeEnd":516,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/python/apache_beam/ml/rag/enrichment/milvus_search.py#L480-L516","documentation":"For keyword (or hybrid) search, _get_keyword_search_data requires each EmbeddableItem to supply at least one query input: text content or a sparse embedding. If both are absent, Milvus has nothing to search with and the enricher raises this ValueError naming the item id.","triggerScenarios":"An EmbeddableItem with empty content.text and empty/None sparse_embedding flows through MilvusEnricher configured with KeywordSearchStrategy or HybridSearchStrategy.","commonSituations":"Documents with empty bodies ingested from a sparse source; sparse embedding step omitted in the pipeline; hybrid search where only dense embeddings were generated and text was cleared after chunking.","solutions":["Populate item.content.text (or the sparse embedding) before enrichment","Add sparse embedding generation to the pipeline when using keyword/hybrid search","Filter out empty-content items before the enricher"],"exampleFix":"// before\nitem = EmbeddableItem(id='1', content=Content(text=''))  # no sparse either\n// after\nitem = EmbeddableItem(id='1', content=Content(text='chunk body'))\n# or provide item.embedding.sparse_embedding via a sparse embedder","handlingStrategy":"validation","validationCode":"bad = [it.id for it in items if not it.content.text and not it.sparse_embedding]\nassert not bad, f'items missing text and sparse embedding: {bad}'","typeGuard":"def keyword_searchable(item) -> bool:\n    return bool(item.content.text) or bool(item.sparse_embedding)","tryCatchPattern":"try:\n    enriched = enricher(items)\nexcept ValueError as e:\n    if 'missing both text content and sparse' in str(e): fallback_to_vector_search(items)\n    else: raise","preventionTips":["Populate content.text for every chunk in keyword/hybrid mode","Generate sparse embeddings when the Milvus collection uses sparse fields","Sanitize empty-text documents at ingestion time"],"tags":["python","apache-beam","milvus","rag","embeddings"],"backgroundTag":"missing-required-argument","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}