File size: 1,452 Bytes
5374a2d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
from typing import Optional

from evoagentx.rag.schema import Query
from evoagentx.core.logging import logger
from .simple_reranker import SimpleReranker
from .base import BasePostprocessor, RerankerType


__all__ = ['PostprocessorFactory', 'SimpleReranker', 'BasePostprocessor']

class PostprocessorFactory:
    """Factory for creating post-processors."""
    
    def create(
        self,
        postprocessor_type: str,
        query: Optional[Query] = None
    ) -> BasePostprocessor:
        """Create a post-processor based on configuration.
        
        Args:
            postprocessor_type (str): Type of post-processor (e.g., 'simple', 'bge').
            query (Query, optional): Query for configuration.
            
        Returns:
            BasePostprocessor: A post-processor instance.
            
        Raises:
            ValueError: If the post-processor type or configuration is invalid.
        """
        if postprocessor_type == RerankerType.SIMPLE:
            if not query:
                raise ValueError("Query required for reranker")
            postprocessor = SimpleReranker(
                similarity_cutoff=query.similarity_cutoff,
                keyword_filters=query.keyword_filters
            )
        else:
            raise ValueError(f"Unsupported post-processor type: {postprocessor_type}")
        
        logger.info(f"Created post-processor: {postprocessor_type}")
        return postprocessor