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 model

  • standard_pipeline_type (PipelineType) -- kind of Hugging Face pipeline

  • standard_model_name (str) -- name of transformers compatible Hugging Face model

  • quantised_model_name (str) -- name of ctransformers compatible Hugging Face model

  • quantised_model_file (str) -- named of quantised model file

  • quantised_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 Face

  • directory_path (pathlib.Path) -- path to directory for storing vector store

  • source_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 Face

  • directory_path (pathlib.Path) -- path to load vector store from

Returns:

vector store

Return type:

Chroma

Notes

  • embedding_model must 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 store

  • search_type (RetrievalType) -- kind of retrieval algorithm for searching vector store

  • number_of_documents (int) -- number of documents to retrieve

  • initial_number_of_documents (int) -- initial number of documents to consider

  • diversity_level (float) -- similarity between retrieved documents

  • language_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.

Parameters:
  • question_answer_chain (RunnableSerializable) -- question answering pipeline

  • question (str) -- query from user

Returns:

  • dict -- response from large language model

  • CaptureDetailsCallback -- callback capturing details of particular run of question answering pipeline

Return type:

tuple[dict, CaptureDetailsCallback]

store_embedding_database(vector_store: Chroma) None#

Dump vector store to disk into configured directory.

Parameters:

vector_store (Chroma) -- vector store