def test_mixed_truncation_strategy(self, mock_search_results):
        """Test mixed truncation strategy combining token count and score."""
        # Function implementing mixed truncation strategy
        def mixed_truncation_strategy(search_results, max_tokens=1000, min_score=0.7):
            # First filter by score
            filtered_results = [r for r in search_results["chunk_search_results"]
                               if r.get("score", 0) >= min_score]

            # Then truncate by tokens
            def estimate_tokens(text):
                return len(text) // 4

            context_items = []
            current_tokens = 0

            for result in filtered_results:
                chunk_text = result["text"]
                chunk_tokens = estimate_tokens(chunk_text)

                if current_tokens + chunk_tokens > max_tokens:
                    break

                context_items.append(chunk_text)
                current_tokens += chunk_tokens

            return "\n\n".join(context_items)

        # Test the mixed strategy
        context = mixed_truncation_strategy(
            mock_search_results,
            max_tokens=50,
            min_score=0.8
        )

        # Check result
        chunk_count = context.count("search result")
        assert 1 <= chunk_count <= 3, "Mixed strategy should limit results appropriately"
Test mixed truncation strategy combining token count and score.
py/tests/unit/retrieval/test_rag_processing.py