def test_default_context_formatting(self, mock_search_results):
        """Test the default formatting of context from search results."""
        # Function to format context
        def format_context(search_results, include_metadata=True):
            context = ""
            for i, result in enumerate(search_results["chunk_search_results"]):
                # Format the chunk text
                chunk_text = f"[{i+1}] {result['text']}"

                # Add metadata if requested
                if include_metadata:
                    metadata_items = []
                    for key, value in result.get("metadata", {}).items():
                        if key not in ["embedding"]:  # Skip non-user-friendly fields
                            metadata_items.append(f"{key}: {value}")

                    if metadata_items:
                        metadata_str = ", ".join(metadata_items)
                        chunk_text += f" ({metadata_str})"

                context += chunk_text + "\n\n"

            return context.strip()

        # Format context with metadata
        context_with_metadata = format_context(mock_search_results)

        # Check formatting
        assert "[1]" in context_with_metadata
        assert "source" in context_with_metadata
        assert "title" in context_with_metadata

        # Format context without metadata
        context_without_metadata = format_context(mock_search_results, include_metadata=False)

        # Check formatting
        assert "[1]" in context_without_metadata
        assert "source" not in context_without_metadata
        assert "title" not in context_without_metadata
Test the default formatting of context from search results.
py/tests/unit/retrieval/test_rag_processing.py