RAGTitan and factory
RAGTitan: the easiest way to use the package.
It builds every part for you, so you only need two calls:
from rag_titan import RAGTitan
rag = RAGTitan(rag_type="simple")
rag.index(["handbook.pdf", "policy.docx"])
print(rag.ask("How many leave days do I get?"))
print(rag.run("How many leave days do I get?")["log"]) # every step
rag.evaluate("questions.json") # end to end, uses the LLM
rag.evaluate_retrieval("questions.json") # search only, fast
rag.evaluate_stages(files, "golden.json") # every stage, scorecard
RAGTitan
One object that can index files and answer questions about them.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
rag_type
|
which RAG to use, "simple" or "adaptive". |
'simple'
|
|
settings
|
optional dict of settings to change, for example {"llm_model": "llama3.2"}. Anything missing uses the value from the environment or the default. |
None
|
Source code in src/rag_titan/app.py
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 | |
ask(question)
Answer a question using the indexed files.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
question
|
the user's question as text. |
required |
Returns:
| Type | Description |
|---|---|
|
The answer text. |
Source code in src/rag_titan/app.py
62 63 64 65 66 67 68 69 70 71 72 | |
evaluate(questions, show=True)
Answer every test question with this RAG type and score the runs (uses the LLM).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
questions
|
path to a questions JSON file, or a list of question dicts. |
required | |
show
|
print the report table. |
True
|
Returns:
| Type | Description |
|---|---|
|
The dict from evaluate_rag(): evidence scores on the chunks given to |
|
|
the LLM, answered share, steps, time, and one row per question. |
Source code in src/rag_titan/app.py
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 | |
evaluate_retrieval(questions, top_k=5, show=True)
Check how well search finds the evidence for test questions (no LLM used).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
questions
|
path to a questions JSON file, or a list of question dicts. |
required | |
top_k
|
how many chunks to retrieve per question. |
5
|
|
show
|
print the report table. |
True
|
Returns:
| Type | Description |
|---|---|
|
The dict from evaluate_retriever(): means, latency and one row per question. |
Source code in src/rag_titan/app.py
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 | |
evaluate_stages(file_paths, questions, k=5, include_embeddings=False, show=True)
Index the files, answer the golden questions and score every stage (uses the LLM).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_paths
|
list of files to index (the index is rebuilt). |
required | |
questions
|
path to a golden questions JSON file, or a list of dicts with "id", "question" and gold labels (see collect_dataset). |
required | |
k
|
how many results to score in the ranking metrics. |
5
|
|
include_embeddings
|
also score the embedding stage. |
False
|
|
show
|
print the overall score, status and first failing stage. |
True
|
Returns:
| Type | Description |
|---|---|
|
The report from RAGEvaluator: one entry per stage, "root_causes" |
|
|
and "scorecard". Save it with ReportManager. |
Source code in src/rag_titan/app.py
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 | |
index(file_paths, reset=True)
Read, chunk, embed and store the given files.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_paths
|
list of paths to .pdf or .docx files. |
required | |
reset
|
when True, remove previously indexed chunks first. |
True
|
Returns:
| Type | Description |
|---|---|
|
The number of chunks stored. |
Source code in src/rag_titan/app.py
49 50 51 52 53 54 55 56 57 58 59 60 | |
run(question)
Answer a question and show every step taken.
Returns:
| Type | Description |
|---|---|
|
The dict from the RAG type's run() ("answer", "sources", "steps"), |
|
|
plus "log": the steps as readable text (see describe_steps). |
Source code in src/rag_titan/app.py
74 75 76 77 78 79 80 81 82 83 84 | |
The only place that knows which class to use for each setting.
Adding a new provider or strategy
- create its class in the right folder
- add one
if name == ...line in the matching build_* function - change the setting in .env (or pass it in
get_settings())
build_agent_llm(settings)
Create the chat model used by agents (it must support tools).
Source code in src/rag_titan/factory.py
52 53 54 | |
build_chunker(settings)
Create the chunker named in settings["chunker"]. chunk_size and chunk_overlap count words, characters or tokens, depending on the chunker.
Source code in src/rag_titan/factory.py
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 | |
build_embedder(settings)
Create the embedding model named in settings["embed_provider"].
Source code in src/rag_titan/factory.py
57 58 59 60 61 62 63 64 65 66 67 | |
build_generator(settings, llm)
Create the answer generator named in settings["generator"].
Source code in src/rag_titan/factory.py
130 131 132 133 134 135 136 137 | |
build_llm(settings, model=None, think=False)
Create the chat model named in settings["llm_provider"].
Source code in src/rag_titan/factory.py
41 42 43 44 45 46 47 48 49 | |
build_rag(rag_type, parts)
Create one RAG type from the parts made by build_rag_parts().
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
rag_type
|
one of RAG_TYPES, for example "simple" or "adaptive". |
required | |
parts
|
the dict returned by build_rag_parts(). |
required |
Source code in src/rag_titan/factory.py
161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 | |
build_rag_parts(settings)
Build every RAG building block, sharing one embedder and one store.
Returns:
| Type | Description |
|---|---|
|
A dict with "llm", "pipeline", "retriever", "reranker" |
|
|
and "generator". |
Source code in src/rag_titan/factory.py
140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 | |
build_reranker(settings, llm=None)
Create the reranker named in settings["reranker"].
llm is not used yet. It is here for future LLM-based rerankers.
Source code in src/rag_titan/factory.py
114 115 116 117 118 119 120 121 122 123 124 125 126 127 | |
build_store(settings)
Create the vector store named in settings["vector_store"].
Source code in src/rag_titan/factory.py
104 105 106 107 108 109 110 111 | |
All settings in one place.
Values are read from environment variables (or a .env file in the
folder where you run your code). Every setting has a safe default, so
the package works without any configuration.
Example
from rag_titan.config import get_settings
settings = get_settings({"llm_model": "llama3.2", "chunk_size": 200})
get_settings(overrides=None)
Build the settings dictionary.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
overrides
|
optional dict of settings that win over the environment, for example {"chunk_size": 200}. |
None
|
Returns:
| Type | Description |
|---|---|
|
A dict with every setting the package uses. |
Source code in src/rag_titan/config.py
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 | |