RAGchain.schema package
Submodules
RAGchain.schema.db_origin module
RAGchain.schema.evaluate_result module
- class RAGchain.schema.evaluate_result.EvaluateResult(results: dict, use_metrics: List[str], each_results: pandas.core.frame.DataFrame)
Bases:
object
- each_results: DataFrame
DataFrame of each results question by question
- results: dict
Dictionary of metrics and their results
- use_metrics: List[str]
List of metrics to use
RAGchain.schema.passage module
- class RAGchain.schema.passage.Passage(*, id: UUID | str = None, content: str, filepath: str, content_datetime: datetime = None, importance: int = 0, previous_passage_id: UUID | str | None = None, next_passage_id: UUID | str | None = None, metadata_etc: dict = None)
Bases:
Serializable
Class for storing a passage and metadatas
- content: str
String text.
- content_datetime: datetime
Datetime when the passage content is created or edited. Everytime passge content changes, this value should be updated.
- copy(*args, **kwargs)
Duplicate a model, optionally choose which fields to include, exclude and change.
- Parameters:
-
include – fields to include in new model
exclude – fields to exclude from new model, as with values this takes precedence over include
update – values to change/add in the new model. Note: the data is not validated before creating the new model: you should trust this data
deep – set to True to make a deep copy of the model
- Returns:
new model instance
- filepath: str
Filepath of the passage.
- classmethod from_documents(documents: List[Document]) List[Passage]
Convert a list of documents to a list of passages. metadata with ‘source’ key is required. It will convert to filepath filed. metadat with ‘content_datetime’ key is optional. It will convert to content_datetime field. It can be datetime.datetime object, or string with ‘%Y-%m-%d %H:%M:%S’ format. metadata with ‘importance’ key is optional. It will convert to importance field. It must be int. :param documents: A list of documents.
- classmethod from_search(search_results: List[Dict[str, str]]) List[Passage]
Convert a list of search results to a list of passages. :param search_results: A list of search results, it requires ‘title’, ‘link’, ‘snippet’ keys.
- id: UUID | str
Unique identifier for the passage. You can use string or UUID. By default, create new UUID for new passage.
- importance: int
Importance of the passage. The higher the value, the more important the passage is. It can be minus value. The default is 0.
- is_exactly_same(other)
- metadata_etc: dict
Arbitrary metadata about the passage.
- next_passage_id: UUID | str | None
Next passage’s id. If this is the last passage, this value should be None.
- previous_passage_id: UUID | str | None
Previous passage’s id. If this is the first passage, this value should be None.
- reset_id()
- to_dict()
- to_document() Document
RAGchain.schema.prompt module
- class RAGchain.schema.prompt.RAGchainChatPromptTemplate(*, name: str | None = None, input_variables: List[str], input_types: Dict[str, Any] = None, output_parser: BaseOutputParser | None = None, partial_variables: Mapping[str, str | Callable[[], str]] = None, messages: List[BaseMessagePromptTemplate | BaseMessage | BaseChatPromptTemplate], validate_template: bool = False)
Bases:
ChatPromptTemplate
- input_variables: List[str]
List of input variables in template messages. Used for validation.
- messages: List[MessageLike]
List of messages consisting of either message prompt templates or messages.
- validate_template: bool
Whether or not to try validating the template.
- class RAGchain.schema.prompt.RAGchainPromptTemplate(*, name: str | None = None, input_variables: List[str], input_types: Dict[str, Any] = None, output_parser: BaseOutputParser | None = None, partial_variables: Mapping[str, str | Callable[[], str]] = None, template: str, template_format: Literal['f-string', 'jinja2'] = 'f-string', validate_template: bool = False)
Bases:
PromptTemplate
- input_variables: List[str]
A list of the names of the variables the prompt template expects.
- template: str
The prompt template.
- template_format: Literal['f-string', 'jinja2']
The format of the prompt template. Options are: ‘f-string’, ‘jinja2’.
- validate_template: bool
Whether or not to try validating the template.
RAGchain.schema.retrieval_result module
- class RAGchain.schema.retrieval_result.RetrievalResult(*, query: str, passages: List[Passage], scores: List[float], metadata: dict = None)
Bases:
BaseModel
class for storing retrieval result
- metadata: dict
metadata that you can store anything you want
- query: str
query string used for retrieval
- scores: List[float]
list of scores for each passage
- slice(start: int = 0, end: int | None = None)
Slice passages and scores. :param start: int, start index of slice. Default is 0. :param end: int, end index of slice. Default is the length of passages.
- to_dict()
- to_prompt_input(passage_convert_func: ~typing.Callable[[~typing.List[~RAGchain.schema.passage.Passage]], str] = <function Passage.make_prompts>) dict