def test_score_threshold_truncation(self, mock_search_results):
        """Test truncating context based on relevance score threshold."""
        # Function to truncate context based on minimum score
        def truncate_context_by_score(search_results, min_score=0.7):
            context_items = []

            # Add chunks that meet the minimum score
            for result in search_results["chunk_search_results"]:
                if result.get("score", 0) >= min_score:
                    context_items.append(result["text"])

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

        # Truncate with high score threshold (should only include top results)
        high_threshold_context = truncate_context_by_score(mock_search_results, min_score=0.85)

        # Check truncation
        high_chunk_count = high_threshold_context.count("search result")
        assert high_chunk_count <= 3, "Should only include top chunks with high score threshold"

        # Truncate with low score threshold (should include most or all chunks)
        low_threshold_context = truncate_context_by_score(mock_search_results, min_score=0.7)
        low_chunk_count = low_threshold_context.count("search result")
        assert low_chunk_count >= 4, "Should include most chunks with low score threshold"
Test truncating context based on relevance score threshold.
py/tests/unit/retrieval/test_rag_processing.py