Multi Document RAG
Multi Document RAG is not as simple as single document QA. zyx
has decided to let the professionals handle this one, and provides a simple interface
for working with Document
objects using the chromadb
library, with a simple wrapper interface.
Example
Lets begin by loading the documents we're going to use for this example.
import zyx
links = [
"https://openreview.net/pdf?id=zAdUB0aCTQ", # AgentBench: Evaluating LLMs as Agents
"https://openreview.net/pdf?id=z8TW0ttBPp", # MathCoder: Seamless Code Integration in LLMs for Enhanced Mathematical Reasoning
"https://openreview.net/pdf?id=yoVq2BGQdP", # Achieving Fairness in Multi-Agent MDP Using Reinforcement Learning
"https://openreview.net/pdf?id=yRrPfKyJQ2", # Conversational Drug Editing Using Retrieval and Domain Feedback
]
documents = zyx.read(links) # Handles lists of links/paths as well
Lets now investigate the documents we read
Output
---
Published as a conference paper at ICLR 2024
AGENT BENCH : EVALUATING LLM S AS AGENTS
Xiao Liu1,*, Hao Yu1,*,†, Hanchen Zhang1,*, Yifan Xu1, Xuanyu Lei1, Hanyu Lai1, Yu Gu2,†,
Hangliang Ding1, Kaiwen
---
Published as a conference paper at ICLR 2024
MATHCODER : S EAMLESS CODE INTEGRATION IN
LLM S FOR ENHANCED MATHEMATICAL REASONING
Ke Wang1,4∗Houxing Ren1∗Aojun Zhou1∗Zimu Lu1∗Sichun Luo3∗
Weikang Shi1∗
---
Published as a conference paper at ICLR 2024
ACHIEVING FAIRNESS IN MULTI -AGENT MDP U SING
REINFORCEMENT LEARNING
Peizhong Ju
Department of ECE
The Ohio State University
Columbus, OH 43210, USA
ju.171
---
Published as a conference paper at ICLR 2024
CONVERSATIONAL DRUG EDITING USING RETRIEVAL
AND DOMAIN FEEDBACK
Shengchao Liu1 *, Jiongxiao Wang2 *, Yijin Yang3, Chengpeng Wang4, Ling Liu5,
Hongyu Guo6,7
Creating a Memory Store
Now lets add our documents to the store
store.add(documents)
# Now we can use the store to search for documents
# One of our papers is about LLM's in the domain of Drug Editing
results = store.search("Drug Editing")
LLM Completions in the Store
# We can also wuery our store with an LLM
response = store.completion("How have LLM's been used in the domain of Drug Editing?")
print(response)
Output
ChatCompletion(
id='chatcmpl-ACvGG7JCm2pCwIZgxNCQa5Iew9HEZ',
choices=[
Choice(
finish_reason='stop',
index=0,
logprobs=None,
message=ChatCompletionMessage(
content='Large Language Models (LLMs) have been utilized in the domain of drug editing primarily for their capabilities in data analysis,
predictive modeling, and natural language processing. They assist in the identification of potential drug candidates by analyzing vast databases of chemical
compounds and biological data. LLMs can predict the interactions between drugs and biological targets, facilitate the design of novel drug molecules, and
streamline the drug discovery process by automating literature reviews and synthesizing relevant information. Moreover, their ability to generate hypotheses and
simulate molecular interactions aids researchers in optimizing drug formulations and improving efficacy. Overall, LLMs enhance efficiency and innovation in drug
editing and development.',
refusal=None,
role='assistant',
function_call=None,
tool_calls=None
)
)
],
created=1727643412,
model='gpt-4o-mini-2024-07-18',
object='chat.completion',
service_tier=None,
system_fingerprint='fp_f85bea6784',
usage=CompletionUsage(completion_tokens=126, prompt_tokens=46, total_tokens=172, completion_tokens_details=CompletionTokensDetails(reasoning_tokens=0))
)
API Reference
Class for storing and retrieving data using Chroma.
Source code in zyx/resources/stores/memory.py
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 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 |
|
__init__(collection_name='my_collection', model_class=None, embedding_api_key=None, location=':memory:', persist_directory='chroma_db', chunk_size=512, model='gpt-4o-mini')
Class for storing and retrieving data using Chroma.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
collection_name
|
str
|
The name of the collection. |
'my_collection'
|
model_class
|
Type[BaseModel]
|
Model class for storing data. |
None
|
embedding_api_key
|
str
|
API key for embedding model. |
None
|
location
|
str
|
":memory:" for in-memory database or a string path for persistent storage. |
':memory:'
|
persist_directory
|
str
|
Directory for persisting Chroma database (if not using in-memory storage). |
'chroma_db'
|
chunk_size
|
int
|
Size of chunks for text splitting. |
512
|
model
|
str
|
Model name for text summarization. |
'gpt-4o-mini'
|
Source code in zyx/resources/stores/memory.py
add(data, metadata=None)
Add documents or data to Chroma.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data
|
Union[str, List[str], Document, List[Document]]
|
The data to add to Chroma. |
required |
metadata
|
Optional[dict]
|
The metadata to add to the data. |
None
|
Source code in zyx/resources/stores/memory.py
completion(messages=None, model=None, top_k=5, tools=None, run_tools=True, response_model=None, mode='tool_call', base_url=None, api_key=None, organization=None, top_p=None, temperature=None, max_tokens=None, max_retries=3, verbose=False)
Perform completion with context from Chroma.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
messages
|
Union[str, List[dict]]
|
The messages to use for the completion. |
None
|
model
|
Optional[str]
|
The model to use for the completion. |
None
|
top_k
|
Optional[int]
|
The number of results to return from the search. |
5
|
tools
|
Optional[List[Union[Callable, dict, BaseModel]]]
|
The tools to use for the completion. |
None
|
run_tools
|
Optional[bool]
|
Whether to run the tools for the completion. |
True
|
response_model
|
Optional[BaseModel]
|
The response model to use for the completion. |
None
|
mode
|
Optional[InstructorMode]
|
The mode to use for the completion. |
'tool_call'
|
base_url
|
Optional[str]
|
The base URL to use for the completion. |
None
|
api_key
|
Optional[str]
|
The API key to use for the completion. |
None
|
organization
|
Optional[str]
|
The organization to use for the completion. |
None
|
top_p
|
Optional[float]
|
The top p to use for the completion. |
None
|
temperature
|
Optional[float]
|
The temperature to use for the completion. |
None
|
max_tokens
|
Optional[int]
|
The maximum number of tokens to generate. |
None
|
max_retries
|
Optional[int]
|
The maximum number of retries to use for the completion. |
3
|
verbose
|
Optional[bool]
|
Whether to print the messages to the console. |
False
|
Source code in zyx/resources/stores/memory.py
255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 |
|
search(query, top_k=5)
Search in Chroma collection.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
query
|
str
|
The query to search for. |
required |
top_k
|
int
|
The number of results to return. |
5
|
Returns:
Name | Type | Description |
---|---|---|
SearchResponse |
SearchResponse
|
The search results. |