RAG Processor¶
- class rag.rag_processor.RAGProcessor(model: str, max_token: int, stream: bool, temperature: float, top_p: float, top_k: int, client)¶
Class implementing the RAG process
- Parameters:
model (str) – LLM Model used for generating chatbot answers
max_token (int)
stream (bool)
temperature (float)
top_p (float)
top_k (int)
client
- create_openai_message(context_docs, query)¶
Format the message to send to the OpenAI API.
- Parameters:
context_docs (str) – Context matching the query according to the retrieval process
query (str) – User input question
- Returns:
Contains the message in the correct format to send to the OpenAI API
- Return type:
list of dict
- create_openai_stream(messages)¶
Create a stream to communicate with OpenAI.
- Parameters:
messages (dict)
- Return type:
chat.completion
- async embed(text_input: EmbeddingRequest)¶
Get the embedding of an embedding request.
- Parameters:
text_input (EmbeddingRequest)
- Returns:
The requested text embedding
- Return type:
dict
- generate(openai_stream, source_url)¶
Generate the answer using LLM.
- Parameters:
openai_stream
source_url
- async process(request: RAGRequest)¶
Execute the RAG process and query the LLM model.
- Parameters:
request (RAGRequest) – User input question
- Returns:
LLM generated answer to the question
- Return type:
str
- async retrieve(request: RAGRequest, language: str = None, k: int = 0)¶
Retrieve context documents related to the user input question.
Only supports retrieval of 1 document at the moment (set in /config/config.yaml).
Todo
multi-doc retrieval later
- Parameters:
request (RAGRequest) – User input question
language (str) – Question and context documents language
k (int, default 0) – Number of context documents to return (need to be revised, current logic in the code is confusing)