zrguo
commited on
Commit
·
fbe2887
1
Parent(s):
483bc22
Update raganything_example.py
Browse files
examples/raganything_example.py
CHANGED
@@ -181,19 +181,55 @@ async def process_with_rag(
|
|
181 |
file_path=file_path, output_dir=output_dir, parse_method="auto"
|
182 |
)
|
183 |
|
184 |
-
# Example queries
|
185 |
-
|
|
|
|
|
|
|
186 |
"What is the main content of the document?",
|
187 |
-
"
|
188 |
-
"Tell me about the experimental results and data tables",
|
189 |
]
|
190 |
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
result = await rag.query_with_multimodal(query, mode="hybrid")
|
195 |
logger.info(f"Answer: {result}")
|
196 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
197 |
except Exception as e:
|
198 |
logger.error(f"Error processing with RAG: {str(e)}")
|
199 |
import traceback
|
|
|
181 |
file_path=file_path, output_dir=output_dir, parse_method="auto"
|
182 |
)
|
183 |
|
184 |
+
# Example queries - demonstrating different query approaches
|
185 |
+
logger.info("\nQuerying processed document:")
|
186 |
+
|
187 |
+
# 1. Pure text queries using aquery()
|
188 |
+
text_queries = [
|
189 |
"What is the main content of the document?",
|
190 |
+
"What are the key topics discussed?",
|
|
|
191 |
]
|
192 |
|
193 |
+
for query in text_queries:
|
194 |
+
logger.info(f"\n[Text Query]: {query}")
|
195 |
+
result = await rag.aquery(query, mode="hybrid")
|
|
|
196 |
logger.info(f"Answer: {result}")
|
197 |
|
198 |
+
# 2. Multimodal query with specific multimodal content using aquery_with_multimodal()
|
199 |
+
logger.info(
|
200 |
+
"\n[Multimodal Query]: Analyzing performance data in context of document"
|
201 |
+
)
|
202 |
+
multimodal_result = await rag.aquery_with_multimodal(
|
203 |
+
"Compare this performance data with any similar results mentioned in the document",
|
204 |
+
multimodal_content=[
|
205 |
+
{
|
206 |
+
"type": "table",
|
207 |
+
"table_data": """Method,Accuracy,Processing_Time
|
208 |
+
RAGAnything,95.2%,120ms
|
209 |
+
Traditional_RAG,87.3%,180ms
|
210 |
+
Baseline,82.1%,200ms""",
|
211 |
+
"table_caption": "Performance comparison results",
|
212 |
+
}
|
213 |
+
],
|
214 |
+
mode="hybrid",
|
215 |
+
)
|
216 |
+
logger.info(f"Answer: {multimodal_result}")
|
217 |
+
|
218 |
+
# 3. Another multimodal query with equation content
|
219 |
+
logger.info("\n[Multimodal Query]: Mathematical formula analysis")
|
220 |
+
equation_result = await rag.aquery_with_multimodal(
|
221 |
+
"Explain this formula and relate it to any mathematical concepts in the document",
|
222 |
+
multimodal_content=[
|
223 |
+
{
|
224 |
+
"type": "equation",
|
225 |
+
"latex": "F1 = 2 \\cdot \\frac{precision \\cdot recall}{precision + recall}",
|
226 |
+
"equation_caption": "F1-score calculation formula",
|
227 |
+
}
|
228 |
+
],
|
229 |
+
mode="hybrid",
|
230 |
+
)
|
231 |
+
logger.info(f"Answer: {equation_result}")
|
232 |
+
|
233 |
except Exception as e:
|
234 |
logger.error(f"Error processing with RAG: {str(e)}")
|
235 |
import traceback
|