generative_ai.information_retrieval.orchestrate_retrieval module#
Define functionalities to orchestrate information retrieval.
- configure_language_model(language_model_type: TransformerType, standard_pipeline_type: PipelineType, standard_model_name: str, quantised_model_name: str, quantised_model_file: str, quantised_model_type: str) QuantisedModel | StandardModel#
Prepare configurations to load language model.
- Parameters:
language_model_type (
TransformerType) -- kind of language modelstandard_pipeline_type (
PipelineType) -- kind of Hugging Face pipelinestandard_model_name (
str) -- name oftransformerscompatible Hugging Face modelquantised_model_name (
str) -- name ofctransformerscompatible Hugging Face modelquantised_model_file (
str) -- named of quantised model filequantised_model_type (
str) -- type of quantised model
- Returns:
configurations of language model
- Return type:
LanguageModel- Raises:
ValueError -- if language model type is not supported
- create_embedding_database(embedding_model: str, directory_path: pathlib.Path, source_documents: list[Document]) Chroma#
Prepare an embedding database.
- Parameters:
embedding_model (
str) -- name of Sentence Transformers model from Hugging Facedirectory_path (
pathlib.Path) -- path to directory for storing vector storesource_documents (
list[Document]) -- partitioned source documents
- Returns:
vector store
- Return type:
Chroma
- load_embedding_database(embedding_model: str, directory_path: pathlib.Path) Chroma#
Load vector store from disk from configured directory.
- Parameters:
embedding_model (
str) -- name of Sentence Transformers model from Hugging Facedirectory_path (
pathlib.Path) -- path to load vector store from
- Returns:
vector store
- Return type:
Chroma
Notes
embedding_modelmust match the one originally used for database creation.
- load_source_documents(file_path: pathlib.Path) list[Document]#
Load and partition source documents.
- Parameters:
file_path (
pathlib.Path) -- path storing JSON dataset- Returns:
partitioned source documents
- Return type:
list[Document]
- prepare_question_answer_chain(embedding_database: Chroma, search_type: RetrievalType, number_of_documents: int, initial_number_of_documents: int, diversity_level: float, language_model: QuantisedModel | StandardModel) RunnableSerializable#
Prepare a question answering pipeline.
- Parameters:
embedding_database (
Chroma) -- vector storesearch_type (
RetrievalType) -- kind of retrieval algorithm for searching vector storenumber_of_documents (
int) -- number of documents to retrieveinitial_number_of_documents (
int) -- initial number of documents to considerdiversity_level (
float) -- similarity between retrieved documentslanguage_model (
LanguageModel) -- configurations of language model
- Returns:
question answering pipeline
- Return type:
RunnableSerializable
- run_question_answer_chain(question_answer_chain: RunnableSerializable, question: str) tuple[dict, CaptureDetailsCallback]#
Run question answering pipeline for user input.