raglib-py 2.0.1__tar.gz → 2.0.3__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (246) hide show
  1. {raglib_py-2.0.1 → raglib_py-2.0.3}/PKG-INFO +1 -1
  2. {raglib_py-2.0.1 → raglib_py-2.0.3}/pyproject.toml +1 -1
  3. {raglib_py-2.0.1 → raglib_py-2.0.3}/raglib/__init__.py +1 -1
  4. {raglib_py-2.0.1 → raglib_py-2.0.3}/raglib/components/hybrid_retriever.py +6 -6
  5. {raglib_py-2.0.1 → raglib_py-2.0.3}/raglib/components/multi_query_retriever.py +2 -3
  6. {raglib_py-2.0.1 → raglib_py-2.0.3}/raglib/core/concurrency.py +103 -74
  7. {raglib_py-2.0.1 → raglib_py-2.0.3}/raglib/embedding/cached_embedding.py +3 -7
  8. {raglib_py-2.0.1 → raglib_py-2.0.3}/raglib/eval/__init__.py +148 -152
  9. {raglib_py-2.0.1 → raglib_py-2.0.3}/raglib/graphrag/communities.py +2 -7
  10. {raglib_py-2.0.1 → raglib_py-2.0.3}/raglib/graphrag/extractor.py +2 -5
  11. {raglib_py-2.0.1 → raglib_py-2.0.3}/raglib/graphrag/search.py +2 -6
  12. {raglib_py-2.0.1 → raglib_py-2.0.3}/raglib/visualize.py +2 -2
  13. raglib_py-2.0.3/site/README.md +18 -0
  14. raglib_py-2.0.3/site/node_modules/@babel/code-frame/LICENSE +22 -0
  15. raglib_py-2.0.3/site/node_modules/@babel/code-frame/README.md +19 -0
  16. raglib_py-2.0.3/site/node_modules/@babel/compat-data/LICENSE +22 -0
  17. raglib_py-2.0.3/site/node_modules/@babel/compat-data/README.md +19 -0
  18. raglib_py-2.0.3/site/node_modules/@babel/core/LICENSE +22 -0
  19. raglib_py-2.0.3/site/node_modules/@babel/core/README.md +19 -0
  20. raglib_py-2.0.3/site/node_modules/@babel/generator/LICENSE +22 -0
  21. raglib_py-2.0.3/site/node_modules/@babel/generator/README.md +19 -0
  22. raglib_py-2.0.3/site/node_modules/@babel/helper-compilation-targets/LICENSE +22 -0
  23. raglib_py-2.0.3/site/node_modules/@babel/helper-compilation-targets/README.md +19 -0
  24. raglib_py-2.0.3/site/node_modules/@babel/helper-globals/LICENSE +22 -0
  25. raglib_py-2.0.3/site/node_modules/@babel/helper-globals/README.md +19 -0
  26. raglib_py-2.0.3/site/node_modules/@babel/helper-module-imports/LICENSE +22 -0
  27. raglib_py-2.0.3/site/node_modules/@babel/helper-module-imports/README.md +19 -0
  28. raglib_py-2.0.3/site/node_modules/@babel/helper-module-transforms/LICENSE +22 -0
  29. raglib_py-2.0.3/site/node_modules/@babel/helper-module-transforms/README.md +19 -0
  30. raglib_py-2.0.3/site/node_modules/@babel/helper-plugin-utils/LICENSE +22 -0
  31. raglib_py-2.0.3/site/node_modules/@babel/helper-plugin-utils/README.md +19 -0
  32. raglib_py-2.0.3/site/node_modules/@babel/helper-string-parser/LICENSE +22 -0
  33. raglib_py-2.0.3/site/node_modules/@babel/helper-string-parser/README.md +19 -0
  34. raglib_py-2.0.3/site/node_modules/@babel/helper-validator-identifier/LICENSE +22 -0
  35. raglib_py-2.0.3/site/node_modules/@babel/helper-validator-identifier/README.md +19 -0
  36. raglib_py-2.0.3/site/node_modules/@babel/helper-validator-option/LICENSE +22 -0
  37. raglib_py-2.0.3/site/node_modules/@babel/helper-validator-option/README.md +19 -0
  38. raglib_py-2.0.3/site/node_modules/@babel/helpers/LICENSE +23 -0
  39. raglib_py-2.0.3/site/node_modules/@babel/helpers/README.md +19 -0
  40. raglib_py-2.0.3/site/node_modules/@babel/parser/LICENSE +19 -0
  41. raglib_py-2.0.3/site/node_modules/@babel/parser/README.md +19 -0
  42. raglib_py-2.0.3/site/node_modules/@babel/plugin-transform-react-jsx-self/LICENSE +22 -0
  43. raglib_py-2.0.3/site/node_modules/@babel/plugin-transform-react-jsx-self/README.md +19 -0
  44. raglib_py-2.0.3/site/node_modules/@babel/plugin-transform-react-jsx-source/LICENSE +22 -0
  45. raglib_py-2.0.3/site/node_modules/@babel/plugin-transform-react-jsx-source/README.md +19 -0
  46. raglib_py-2.0.3/site/node_modules/@babel/template/LICENSE +22 -0
  47. raglib_py-2.0.3/site/node_modules/@babel/template/README.md +19 -0
  48. raglib_py-2.0.3/site/node_modules/@babel/traverse/LICENSE +22 -0
  49. raglib_py-2.0.3/site/node_modules/@babel/traverse/README.md +19 -0
  50. raglib_py-2.0.3/site/node_modules/@babel/types/LICENSE +22 -0
  51. raglib_py-2.0.3/site/node_modules/@babel/types/README.md +19 -0
  52. raglib_py-2.0.3/site/node_modules/@esbuild/win32-x64/README.md +3 -0
  53. raglib_py-2.0.3/site/node_modules/@jridgewell/gen-mapping/LICENSE +19 -0
  54. raglib_py-2.0.3/site/node_modules/@jridgewell/gen-mapping/README.md +227 -0
  55. raglib_py-2.0.3/site/node_modules/@jridgewell/remapping/LICENSE +19 -0
  56. raglib_py-2.0.3/site/node_modules/@jridgewell/remapping/README.md +218 -0
  57. raglib_py-2.0.3/site/node_modules/@jridgewell/resolve-uri/LICENSE +19 -0
  58. raglib_py-2.0.3/site/node_modules/@jridgewell/resolve-uri/README.md +40 -0
  59. raglib_py-2.0.3/site/node_modules/@jridgewell/sourcemap-codec/LICENSE +19 -0
  60. raglib_py-2.0.3/site/node_modules/@jridgewell/sourcemap-codec/README.md +264 -0
  61. raglib_py-2.0.3/site/node_modules/@jridgewell/trace-mapping/LICENSE +19 -0
  62. raglib_py-2.0.3/site/node_modules/@jridgewell/trace-mapping/README.md +348 -0
  63. raglib_py-2.0.3/site/node_modules/@rolldown/pluginutils/LICENSE +25 -0
  64. raglib_py-2.0.3/site/node_modules/@rollup/rollup-win32-x64-gnu/README.md +3 -0
  65. raglib_py-2.0.3/site/node_modules/@rollup/rollup-win32-x64-msvc/README.md +3 -0
  66. raglib_py-2.0.3/site/node_modules/@types/babel__core/LICENSE +21 -0
  67. raglib_py-2.0.3/site/node_modules/@types/babel__core/README.md +15 -0
  68. raglib_py-2.0.3/site/node_modules/@types/babel__generator/LICENSE +21 -0
  69. raglib_py-2.0.3/site/node_modules/@types/babel__generator/README.md +15 -0
  70. raglib_py-2.0.3/site/node_modules/@types/babel__template/LICENSE +21 -0
  71. raglib_py-2.0.3/site/node_modules/@types/babel__template/README.md +15 -0
  72. raglib_py-2.0.3/site/node_modules/@types/babel__traverse/LICENSE +21 -0
  73. raglib_py-2.0.3/site/node_modules/@types/babel__traverse/README.md +15 -0
  74. raglib_py-2.0.3/site/node_modules/@types/estree/LICENSE +21 -0
  75. raglib_py-2.0.3/site/node_modules/@types/estree/README.md +15 -0
  76. raglib_py-2.0.3/site/node_modules/@types/prop-types/LICENSE +21 -0
  77. raglib_py-2.0.3/site/node_modules/@types/prop-types/README.md +15 -0
  78. raglib_py-2.0.3/site/node_modules/@types/react/LICENSE +21 -0
  79. raglib_py-2.0.3/site/node_modules/@types/react/README.md +15 -0
  80. raglib_py-2.0.3/site/node_modules/@types/react-dom/LICENSE +21 -0
  81. raglib_py-2.0.3/site/node_modules/@types/react-dom/README.md +15 -0
  82. raglib_py-2.0.3/site/node_modules/@vitejs/plugin-react/LICENSE +21 -0
  83. raglib_py-2.0.3/site/node_modules/@vitejs/plugin-react/README.md +142 -0
  84. raglib_py-2.0.3/site/node_modules/baseline-browser-mapping/README.md +545 -0
  85. raglib_py-2.0.3/site/node_modules/browserslist/LICENSE +20 -0
  86. raglib_py-2.0.3/site/node_modules/browserslist/README.md +66 -0
  87. raglib_py-2.0.3/site/node_modules/caniuse-lite/LICENSE +395 -0
  88. raglib_py-2.0.3/site/node_modules/caniuse-lite/README.md +3 -0
  89. raglib_py-2.0.3/site/node_modules/convert-source-map/LICENSE +23 -0
  90. raglib_py-2.0.3/site/node_modules/convert-source-map/README.md +206 -0
  91. raglib_py-2.0.3/site/node_modules/csstype/LICENSE +19 -0
  92. raglib_py-2.0.3/site/node_modules/csstype/README.md +291 -0
  93. raglib_py-2.0.3/site/node_modules/debug/LICENSE +20 -0
  94. raglib_py-2.0.3/site/node_modules/debug/README.md +481 -0
  95. raglib_py-2.0.3/site/node_modules/electron-to-chromium/LICENSE +5 -0
  96. raglib_py-2.0.3/site/node_modules/electron-to-chromium/README.md +186 -0
  97. raglib_py-2.0.3/site/node_modules/esbuild/README.md +3 -0
  98. raglib_py-2.0.3/site/node_modules/gensync/LICENSE +7 -0
  99. raglib_py-2.0.3/site/node_modules/gensync/README.md +196 -0
  100. raglib_py-2.0.3/site/node_modules/js-tokens/LICENSE +21 -0
  101. raglib_py-2.0.3/site/node_modules/js-tokens/README.md +240 -0
  102. raglib_py-2.0.3/site/node_modules/jsesc/README.md +422 -0
  103. raglib_py-2.0.3/site/node_modules/json5/README.md +282 -0
  104. raglib_py-2.0.3/site/node_modules/loose-envify/LICENSE +21 -0
  105. raglib_py-2.0.3/site/node_modules/loose-envify/README.md +45 -0
  106. raglib_py-2.0.3/site/node_modules/lru-cache/LICENSE +15 -0
  107. raglib_py-2.0.3/site/node_modules/lru-cache/README.md +166 -0
  108. raglib_py-2.0.3/site/node_modules/nanoid/LICENSE +20 -0
  109. raglib_py-2.0.3/site/node_modules/nanoid/README.md +39 -0
  110. raglib_py-2.0.3/site/node_modules/node-releases/LICENSE +21 -0
  111. raglib_py-2.0.3/site/node_modules/node-releases/README.md +32 -0
  112. raglib_py-2.0.3/site/node_modules/picocolors/LICENSE +15 -0
  113. raglib_py-2.0.3/site/node_modules/picocolors/README.md +21 -0
  114. raglib_py-2.0.3/site/node_modules/postcss/LICENSE +20 -0
  115. raglib_py-2.0.3/site/node_modules/postcss/README.md +27 -0
  116. raglib_py-2.0.3/site/node_modules/react/LICENSE +21 -0
  117. raglib_py-2.0.3/site/node_modules/react/README.md +37 -0
  118. raglib_py-2.0.3/site/node_modules/react-dom/LICENSE +21 -0
  119. raglib_py-2.0.3/site/node_modules/react-dom/README.md +60 -0
  120. raglib_py-2.0.3/site/node_modules/react-refresh/LICENSE +21 -0
  121. raglib_py-2.0.3/site/node_modules/react-refresh/README.md +5 -0
  122. raglib_py-2.0.3/site/node_modules/rollup/README.md +134 -0
  123. raglib_py-2.0.3/site/node_modules/scheduler/LICENSE +21 -0
  124. raglib_py-2.0.3/site/node_modules/scheduler/README.md +9 -0
  125. raglib_py-2.0.3/site/node_modules/semver/LICENSE +15 -0
  126. raglib_py-2.0.3/site/node_modules/semver/README.md +443 -0
  127. raglib_py-2.0.3/site/node_modules/source-map-js/LICENSE +28 -0
  128. raglib_py-2.0.3/site/node_modules/source-map-js/README.md +765 -0
  129. raglib_py-2.0.3/site/node_modules/typescript/README.md +50 -0
  130. raglib_py-2.0.3/site/node_modules/update-browserslist-db/LICENSE +20 -0
  131. raglib_py-2.0.3/site/node_modules/update-browserslist-db/README.md +41 -0
  132. raglib_py-2.0.3/site/node_modules/vite/README.md +20 -0
  133. raglib_py-2.0.3/site/node_modules/yallist/LICENSE +15 -0
  134. raglib_py-2.0.3/site/node_modules/yallist/README.md +204 -0
  135. {raglib_py-2.0.1 → raglib_py-2.0.3}/.gitignore +0 -0
  136. {raglib_py-2.0.1 → raglib_py-2.0.3}/LICENSE +0 -0
  137. {raglib_py-2.0.1 → raglib_py-2.0.3}/README.md +0 -0
  138. {raglib_py-2.0.1 → raglib_py-2.0.3}/raglib/__main__.py +0 -0
  139. {raglib_py-2.0.1 → raglib_py-2.0.3}/raglib/cli.py +0 -0
  140. {raglib_py-2.0.1 → raglib_py-2.0.3}/raglib/components/__init__.py +0 -0
  141. {raglib_py-2.0.1 → raglib_py-2.0.3}/raglib/components/bm25.py +0 -0
  142. {raglib_py-2.0.1 → raglib_py-2.0.3}/raglib/components/context_reducer.py +0 -0
  143. {raglib_py-2.0.1 → raglib_py-2.0.3}/raglib/components/decision.py +0 -0
  144. {raglib_py-2.0.1 → raglib_py-2.0.3}/raglib/components/deduplicator.py +0 -0
  145. {raglib_py-2.0.1 → raglib_py-2.0.3}/raglib/components/evaluator.py +0 -0
  146. {raglib_py-2.0.1 → raglib_py-2.0.3}/raglib/components/generator.py +0 -0
  147. {raglib_py-2.0.1 → raglib_py-2.0.3}/raglib/components/grader.py +0 -0
  148. {raglib_py-2.0.1 → raglib_py-2.0.3}/raglib/components/memory.py +0 -0
  149. {raglib_py-2.0.1 → raglib_py-2.0.3}/raglib/components/multi_hop_retriever.py +0 -0
  150. {raglib_py-2.0.1 → raglib_py-2.0.3}/raglib/components/planner.py +0 -0
  151. {raglib_py-2.0.1 → raglib_py-2.0.3}/raglib/components/query_expander.py +0 -0
  152. {raglib_py-2.0.1 → raglib_py-2.0.3}/raglib/components/query_rewriter.py +0 -0
  153. {raglib_py-2.0.1 → raglib_py-2.0.3}/raglib/components/refiner.py +0 -0
  154. {raglib_py-2.0.1 → raglib_py-2.0.3}/raglib/components/reflection.py +0 -0
  155. {raglib_py-2.0.1 → raglib_py-2.0.3}/raglib/components/reranker.py +0 -0
  156. {raglib_py-2.0.1 → raglib_py-2.0.3}/raglib/components/retriever.py +0 -0
  157. {raglib_py-2.0.1 → raglib_py-2.0.3}/raglib/components/router_retriever.py +0 -0
  158. {raglib_py-2.0.1 → raglib_py-2.0.3}/raglib/components/tools.py +0 -0
  159. {raglib_py-2.0.1 → raglib_py-2.0.3}/raglib/components/web_retriever.py +0 -0
  160. {raglib_py-2.0.1 → raglib_py-2.0.3}/raglib/constants.py +0 -0
  161. {raglib_py-2.0.1 → raglib_py-2.0.3}/raglib/core/__init__.py +0 -0
  162. {raglib_py-2.0.1 → raglib_py-2.0.3}/raglib/core/base.py +0 -0
  163. {raglib_py-2.0.1 → raglib_py-2.0.3}/raglib/core/fusion.py +0 -0
  164. {raglib_py-2.0.1 → raglib_py-2.0.3}/raglib/core/intents.py +0 -0
  165. {raglib_py-2.0.1 → raglib_py-2.0.3}/raglib/core/parsing.py +0 -0
  166. {raglib_py-2.0.1 → raglib_py-2.0.3}/raglib/core/text.py +0 -0
  167. {raglib_py-2.0.1 → raglib_py-2.0.3}/raglib/core/tracing.py +0 -0
  168. {raglib_py-2.0.1 → raglib_py-2.0.3}/raglib/embedding/__init__.py +0 -0
  169. {raglib_py-2.0.1 → raglib_py-2.0.3}/raglib/embedding/base_embedding.py +0 -0
  170. {raglib_py-2.0.1 → raglib_py-2.0.3}/raglib/embedding/embedding_factory.py +0 -0
  171. {raglib_py-2.0.1 → raglib_py-2.0.3}/raglib/embedding/google_embedding.py +0 -0
  172. {raglib_py-2.0.1 → raglib_py-2.0.3}/raglib/embedding/huggingface_embedding.py +0 -0
  173. {raglib_py-2.0.1 → raglib_py-2.0.3}/raglib/embedding/mock_embedding.py +0 -0
  174. {raglib_py-2.0.1 → raglib_py-2.0.3}/raglib/embedding/ollama_embedding.py +0 -0
  175. {raglib_py-2.0.1 → raglib_py-2.0.3}/raglib/embedding/openai_embedding.py +0 -0
  176. {raglib_py-2.0.1 → raglib_py-2.0.3}/raglib/facade.py +0 -0
  177. {raglib_py-2.0.1 → raglib_py-2.0.3}/raglib/graph_context/__init__.py +0 -0
  178. {raglib_py-2.0.1 → raglib_py-2.0.3}/raglib/graph_context/engine.py +0 -0
  179. {raglib_py-2.0.1 → raglib_py-2.0.3}/raglib/graph_context/schemas.py +0 -0
  180. {raglib_py-2.0.1 → raglib_py-2.0.3}/raglib/graphrag/__init__.py +0 -0
  181. {raglib_py-2.0.1 → raglib_py-2.0.3}/raglib/graphrag/indexer.py +0 -0
  182. {raglib_py-2.0.1 → raglib_py-2.0.3}/raglib/graphrag/schemas.py +0 -0
  183. {raglib_py-2.0.1 → raglib_py-2.0.3}/raglib/graphrag/store/__init__.py +0 -0
  184. {raglib_py-2.0.1 → raglib_py-2.0.3}/raglib/graphrag/store/base.py +0 -0
  185. {raglib_py-2.0.1 → raglib_py-2.0.3}/raglib/graphrag/store/neo4j_store.py +0 -0
  186. {raglib_py-2.0.1 → raglib_py-2.0.3}/raglib/graphrag/store/networkx_store.py +0 -0
  187. {raglib_py-2.0.1 → raglib_py-2.0.3}/raglib/llm/__init__.py +0 -0
  188. {raglib_py-2.0.1 → raglib_py-2.0.3}/raglib/llm/base_client.py +0 -0
  189. {raglib_py-2.0.1 → raglib_py-2.0.3}/raglib/llm/constants.py +0 -0
  190. {raglib_py-2.0.1 → raglib_py-2.0.3}/raglib/llm/langchain_adapter.py +0 -0
  191. {raglib_py-2.0.1 → raglib_py-2.0.3}/raglib/llm/mock_client.py +0 -0
  192. {raglib_py-2.0.1 → raglib_py-2.0.3}/raglib/llm/provider_detector.py +0 -0
  193. {raglib_py-2.0.1 → raglib_py-2.0.3}/raglib/llm/providers.py +0 -0
  194. {raglib_py-2.0.1 → raglib_py-2.0.3}/raglib/llm/resilience.py +0 -0
  195. {raglib_py-2.0.1 → raglib_py-2.0.3}/raglib/loaders/__init__.py +0 -0
  196. {raglib_py-2.0.1 → raglib_py-2.0.3}/raglib/loaders/chunk_splitter.py +0 -0
  197. {raglib_py-2.0.1 → raglib_py-2.0.3}/raglib/loaders/document_loader.py +0 -0
  198. {raglib_py-2.0.1 → raglib_py-2.0.3}/raglib/loaders/exceptions.py +0 -0
  199. {raglib_py-2.0.1 → raglib_py-2.0.3}/raglib/loaders/pdf_loader.py +0 -0
  200. {raglib_py-2.0.1 → raglib_py-2.0.3}/raglib/loaders/pptx_loader.py +0 -0
  201. {raglib_py-2.0.1 → raglib_py-2.0.3}/raglib/loaders/text_loader.py +0 -0
  202. {raglib_py-2.0.1 → raglib_py-2.0.3}/raglib/loaders/web_loader.py +0 -0
  203. {raglib_py-2.0.1 → raglib_py-2.0.3}/raglib/loaders/word_loader.py +0 -0
  204. {raglib_py-2.0.1 → raglib_py-2.0.3}/raglib/preprocessing/__init__.py +0 -0
  205. {raglib_py-2.0.1 → raglib_py-2.0.3}/raglib/preprocessing/chunk_splitter.py +0 -0
  206. {raglib_py-2.0.1 → raglib_py-2.0.3}/raglib/providers/__init__.py +0 -0
  207. {raglib_py-2.0.1 → raglib_py-2.0.3}/raglib/providers/base_provider.py +0 -0
  208. {raglib_py-2.0.1 → raglib_py-2.0.3}/raglib/providers/bing_provider.py +0 -0
  209. {raglib_py-2.0.1 → raglib_py-2.0.3}/raglib/providers/brave_provider.py +0 -0
  210. {raglib_py-2.0.1 → raglib_py-2.0.3}/raglib/providers/duckduckgo_provider.py +0 -0
  211. {raglib_py-2.0.1 → raglib_py-2.0.3}/raglib/providers/exa_provider.py +0 -0
  212. {raglib_py-2.0.1 → raglib_py-2.0.3}/raglib/providers/factory.py +0 -0
  213. {raglib_py-2.0.1 → raglib_py-2.0.3}/raglib/providers/google_cse_provider.py +0 -0
  214. {raglib_py-2.0.1 → raglib_py-2.0.3}/raglib/providers/searxng_provider.py +0 -0
  215. {raglib_py-2.0.1 → raglib_py-2.0.3}/raglib/providers/serpapi_provider.py +0 -0
  216. {raglib_py-2.0.1 → raglib_py-2.0.3}/raglib/providers/tavily_provider.py +0 -0
  217. {raglib_py-2.0.1 → raglib_py-2.0.3}/raglib/quick.py +0 -0
  218. {raglib_py-2.0.1 → raglib_py-2.0.3}/raglib/rag_types/__init__.py +0 -0
  219. {raglib_py-2.0.1 → raglib_py-2.0.3}/raglib/rag_types/advanced_rag.py +0 -0
  220. {raglib_py-2.0.1 → raglib_py-2.0.3}/raglib/rag_types/agentic_rag.py +0 -0
  221. {raglib_py-2.0.1 → raglib_py-2.0.3}/raglib/rag_types/corrective_rag.py +0 -0
  222. {raglib_py-2.0.1 → raglib_py-2.0.3}/raglib/rag_types/graph_rag.py +0 -0
  223. {raglib_py-2.0.1 → raglib_py-2.0.3}/raglib/rag_types/hybrid_rag.py +0 -0
  224. {raglib_py-2.0.1 → raglib_py-2.0.3}/raglib/rag_types/memory_rag.py +0 -0
  225. {raglib_py-2.0.1 → raglib_py-2.0.3}/raglib/rag_types/multi_hop_rag.py +0 -0
  226. {raglib_py-2.0.1 → raglib_py-2.0.3}/raglib/rag_types/multi_query_rag.py +0 -0
  227. {raglib_py-2.0.1 → raglib_py-2.0.3}/raglib/rag_types/naive_rag.py +0 -0
  228. {raglib_py-2.0.1 → raglib_py-2.0.3}/raglib/rag_types/routing_rag.py +0 -0
  229. {raglib_py-2.0.1 → raglib_py-2.0.3}/raglib/rag_types/self_rag.py +0 -0
  230. {raglib_py-2.0.1 → raglib_py-2.0.3}/raglib/rag_types/tool_augmented_rag.py +0 -0
  231. {raglib_py-2.0.1 → raglib_py-2.0.3}/raglib/rag_types/web_rag.py +0 -0
  232. {raglib_py-2.0.1 → raglib_py-2.0.3}/raglib/schemas.py +0 -0
  233. {raglib_py-2.0.1 → raglib_py-2.0.3}/raglib/session/__init__.py +0 -0
  234. {raglib_py-2.0.1 → raglib_py-2.0.3}/raglib/session/interactive.py +0 -0
  235. {raglib_py-2.0.1 → raglib_py-2.0.3}/raglib/vectorstores/__init__.py +0 -0
  236. {raglib_py-2.0.1 → raglib_py-2.0.3}/raglib/vectorstores/base_store.py +0 -0
  237. {raglib_py-2.0.1 → raglib_py-2.0.3}/raglib/vectorstores/chroma_store.py +0 -0
  238. {raglib_py-2.0.1 → raglib_py-2.0.3}/raglib/vectorstores/factory.py +0 -0
  239. {raglib_py-2.0.1 → raglib_py-2.0.3}/raglib/vectorstores/in_memory_store.py +0 -0
  240. {raglib_py-2.0.1 → raglib_py-2.0.3}/raglib/vision/__init__.py +0 -0
  241. {raglib_py-2.0.1 → raglib_py-2.0.3}/raglib/vision/anthropic_vision.py +0 -0
  242. {raglib_py-2.0.1 → raglib_py-2.0.3}/raglib/vision/base_vision.py +0 -0
  243. {raglib_py-2.0.1 → raglib_py-2.0.3}/raglib/vision/google_vision.py +0 -0
  244. {raglib_py-2.0.1 → raglib_py-2.0.3}/raglib/vision/mock_vision.py +0 -0
  245. {raglib_py-2.0.1 → raglib_py-2.0.3}/raglib/vision/openai_vision.py +0 -0
  246. {raglib_py-2.0.1 → raglib_py-2.0.3}/raglib/vision/vision_factory.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: raglib-py
3
- Version: 2.0.1
3
+ Version: 2.0.3
4
4
  Summary: Modular Retrieval-Augmented Generation: hybrid search, reranking, CRAG, Self-RAG, agentic and GraphRAG pipelines
5
5
  Project-URL: Homepage, https://github.com/himanshuhs9011/raglib
6
6
  Project-URL: Documentation, https://github.com/himanshuhs9011/raglib/blob/main/docs/USAGE.md
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "raglib-py"
7
- version = "2.0.1"
7
+ version = "2.0.3"
8
8
  description = "Modular Retrieval-Augmented Generation: hybrid search, reranking, CRAG, Self-RAG, agentic and GraphRAG pipelines"
9
9
  readme = "README.md"
10
10
  license = { file = "LICENSE" }
@@ -107,4 +107,4 @@ __all__ = [
107
107
  "GraphContextWindow",
108
108
  ]
109
109
 
110
- __version__ = "2.0.1"
110
+ __version__ = "2.0.3"
@@ -3,9 +3,9 @@
3
3
  from __future__ import annotations
4
4
 
5
5
  import logging
6
- from concurrent.futures import ThreadPoolExecutor
7
6
  from typing import Any, List, Optional
8
7
 
8
+ from raglib.core.concurrency import parallel_map
9
9
  from raglib.components.retriever import Retriever
10
10
  from raglib.components.web_retriever import WebRetriever
11
11
  from raglib.core.fusion import interleave
@@ -54,11 +54,11 @@ class HybridRetriever:
54
54
  def retrieve(self, query: str, **kwargs: Any) -> List[Document]:
55
55
  """Retrieve from both sources in parallel and allocate top_k slots by weight."""
56
56
 
57
- with ThreadPoolExecutor(max_workers=2) as pool:
58
- vector_future = pool.submit(self.vector_retriever.retrieve, query, **kwargs) if self.vector_weight > 0 else None
59
- web_future = pool.submit(self.web_retriever.retrieve, query) if self.web_weight > 0 else None
60
- vector_docs = vector_future.result() if vector_future else []
61
- web_docs = web_future.result() if web_future else []
57
+ tasks = [
58
+ (lambda: self.vector_retriever.retrieve(query, **kwargs)) if self.vector_weight > 0 else (lambda: []),
59
+ (lambda: self.web_retriever.retrieve(query)) if self.web_weight > 0 else (lambda: []),
60
+ ]
61
+ vector_docs, web_docs = parallel_map(lambda task: task(), tasks, max_workers=2)
62
62
  fused = self.allocate(vector_docs, web_docs)
63
63
  logger.info("HybridRetriever fused %d corpus + %d web docs", len(vector_docs), len(web_docs))
64
64
  return fused
@@ -3,9 +3,9 @@
3
3
  from __future__ import annotations
4
4
 
5
5
  import logging
6
- from concurrent.futures import ThreadPoolExecutor
7
6
  from typing import Any, List, Optional
8
7
 
8
+ from raglib.core.concurrency import parallel_map
9
9
  from raglib.components.deduplicator import Deduplicator
10
10
  from raglib.components.query_expander import QueryExpander
11
11
  from raglib.components.retriever import Retriever
@@ -47,8 +47,7 @@ class MultiQueryRetriever:
47
47
  if len(variants) == 1:
48
48
  ranked_lists = [self.retriever.retrieve(variants[0], top_k=k, **kwargs)]
49
49
  else:
50
- with ThreadPoolExecutor(max_workers=min(self.max_workers, len(variants))) as pool:
51
- ranked_lists = list(pool.map(lambda v: self.retriever.retrieve(v, top_k=k, **kwargs), variants))
50
+ ranked_lists = parallel_map(lambda v: self.retriever.retrieve(v, top_k=k, **kwargs), variants, self.max_workers)
52
51
  # The original query gets a higher weight than paraphrases.
53
52
  weights = [1.5] + [1.0] * (len(ranked_lists) - 1)
54
53
  fused = reciprocal_rank_fusion(ranked_lists, weights=weights)
@@ -1,74 +1,103 @@
1
- """Concurrency primitives."""
2
-
3
- from __future__ import annotations
4
-
5
- import threading
6
- from contextlib import contextmanager
7
- from typing import Iterator
8
-
9
-
10
- class ReadWriteLock:
11
- """Many concurrent readers OR one writer (writer-preferring, so ingestion can't starve).
12
-
13
- Queries take the read side, so concurrent chat sessions don't block each other;
14
- ``add`` / ``delete`` take the write side for the short moment they mutate indexes.
15
- Re-entrant for the writer thread (a writer may also read).
16
- """
17
-
18
- def __init__(self) -> None:
19
- """Create an unlocked lock."""
20
-
21
- self._cond = threading.Condition(threading.Lock())
22
- self._readers = 0
23
- self._writer: int = 0 # thread id of the active writer
24
- self._writer_depth = 0
25
- self._waiting_writers = 0
26
-
27
- @contextmanager
28
- def read(self) -> Iterator[None]:
29
- """Shared access."""
30
-
31
- me = threading.get_ident()
32
- with self._cond:
33
- if self._writer == me: # writer reading its own state
34
- self._writer_depth += 1
35
- reentrant = True
36
- else:
37
- reentrant = False
38
- while self._writer or self._waiting_writers:
39
- self._cond.wait()
40
- self._readers += 1
41
- try:
42
- yield
43
- finally:
44
- with self._cond:
45
- if reentrant:
46
- self._writer_depth -= 1
47
- else:
48
- self._readers -= 1
49
- if self._readers == 0:
50
- self._cond.notify_all()
51
-
52
- @contextmanager
53
- def write(self) -> Iterator[None]:
54
- """Exclusive access."""
55
-
56
- me = threading.get_ident()
57
- with self._cond:
58
- if self._writer == me:
59
- self._writer_depth += 1
60
- else:
61
- self._waiting_writers += 1
62
- while self._writer or self._readers:
63
- self._cond.wait()
64
- self._waiting_writers -= 1
65
- self._writer = me
66
- self._writer_depth = 1
67
- try:
68
- yield
69
- finally:
70
- with self._cond:
71
- self._writer_depth -= 1
72
- if self._writer_depth == 0:
73
- self._writer = 0
74
- self._cond.notify_all()
1
+ """Concurrency primitives."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import sys
6
+ import threading
7
+ from concurrent.futures import ThreadPoolExecutor
8
+ from contextlib import contextmanager
9
+ from typing import Callable, Iterator, List, Sequence, TypeVar
10
+
11
+ T = TypeVar("T")
12
+ R = TypeVar("R")
13
+
14
+
15
+ class ReadWriteLock:
16
+ """Many concurrent readers OR one writer (writer-preferring, so ingestion can't starve).
17
+
18
+ Queries take the read side, so concurrent chat sessions don't block each other;
19
+ ``add`` / ``delete`` take the write side for the short moment they mutate indexes.
20
+ Re-entrant for the writer thread (a writer may also read).
21
+ """
22
+
23
+ def __init__(self) -> None:
24
+ """Create an unlocked lock."""
25
+
26
+ self._cond = threading.Condition(threading.Lock())
27
+ self._readers = 0
28
+ self._writer: int = 0 # thread id of the active writer
29
+ self._writer_depth = 0
30
+ self._waiting_writers = 0
31
+
32
+ @contextmanager
33
+ def read(self) -> Iterator[None]:
34
+ """Shared access."""
35
+
36
+ me = threading.get_ident()
37
+ with self._cond:
38
+ if self._writer == me: # writer reading its own state
39
+ self._writer_depth += 1
40
+ reentrant = True
41
+ else:
42
+ reentrant = False
43
+ while self._writer or self._waiting_writers:
44
+ self._cond.wait()
45
+ self._readers += 1
46
+ try:
47
+ yield
48
+ finally:
49
+ with self._cond:
50
+ if reentrant:
51
+ self._writer_depth -= 1
52
+ else:
53
+ self._readers -= 1
54
+ if self._readers == 0:
55
+ self._cond.notify_all()
56
+
57
+ @contextmanager
58
+ def write(self) -> Iterator[None]:
59
+ """Exclusive access."""
60
+
61
+ me = threading.get_ident()
62
+ with self._cond:
63
+ if self._writer == me:
64
+ self._writer_depth += 1
65
+ else:
66
+ self._waiting_writers += 1
67
+ while self._writer or self._readers:
68
+ self._cond.wait()
69
+ self._waiting_writers -= 1
70
+ self._writer = me
71
+ self._writer_depth = 1
72
+ try:
73
+ yield
74
+ finally:
75
+ with self._cond:
76
+ self._writer_depth -= 1
77
+ if self._writer_depth == 0:
78
+ self._writer = 0
79
+ self._cond.notify_all()
80
+
81
+
82
+ # Browsers (Pyodide) and WASI runtimes cannot start threads.
83
+ THREADS_AVAILABLE = sys.platform not in ("emscripten", "wasi")
84
+
85
+
86
+ def parallel_map(fn: Callable[[T], R], items: Sequence[T], max_workers: int) -> List[R]:
87
+ """``[fn(x) for x in items]``, run on a thread pool when that helps and is possible.
88
+
89
+ Falls back to sequential execution when threads are unavailable (Pyodide / WASI) or
90
+ cannot be started, so raglib also runs inside a browser.
91
+ """
92
+
93
+ items = list(items)
94
+ workers = min(max_workers, len(items))
95
+ if workers <= 1 or not THREADS_AVAILABLE:
96
+ return [fn(item) for item in items]
97
+ try:
98
+ with ThreadPoolExecutor(max_workers=workers) as pool:
99
+ return list(pool.map(fn, items))
100
+ except RuntimeError as exc:
101
+ if "thread" not in str(exc).lower():
102
+ raise
103
+ return [fn(item) for item in items]
@@ -5,10 +5,10 @@ from __future__ import annotations
5
5
  import hashlib
6
6
  import logging
7
7
  import threading
8
- from concurrent.futures import ThreadPoolExecutor
9
8
  from collections import OrderedDict
10
9
  from typing import Dict, List, Optional
11
10
 
11
+ from raglib.core.concurrency import parallel_map
12
12
  from raglib.embedding.base_embedding import BaseEmbedding
13
13
  from raglib.llm.resilience import RateLimiter, retry_call
14
14
 
@@ -101,12 +101,8 @@ class CachedEmbedding(BaseEmbedding):
101
101
  raise RuntimeError(f"Embedding model returned {len(vectors)} vectors for {len(batch_indexes)} texts")
102
102
  return vectors
103
103
 
104
- if len(batches) > 1 and self.max_concurrency > 1:
105
- # Embedding APIs are I/O bound: send several batches at once.
106
- with ThreadPoolExecutor(max_workers=min(self.max_concurrency, len(batches))) as pool:
107
- outputs = list(pool.map(embed_batch, batches))
108
- else:
109
- outputs = [embed_batch(batch) for batch in batches]
104
+ # Embedding APIs are I/O bound: send several batches at once.
105
+ outputs = parallel_map(embed_batch, batches, self.max_concurrency)
110
106
  for batch_indexes, vectors in zip(batches, outputs):
111
107
  for index, vector in zip(batch_indexes, vectors):
112
108
  results[index] = list(vector)
@@ -1,152 +1,148 @@
1
- """Evaluation for RAG pipelines: retrieval metrics + LLM-judged answer quality."""
2
-
3
- from __future__ import annotations
4
-
5
- import logging
6
- import math
7
- import statistics
8
- from concurrent.futures import ThreadPoolExecutor
9
- from dataclasses import dataclass, field
10
- from typing import Any, Dict, List, Optional, Sequence
11
-
12
- from raglib.core.parsing import parse_json
13
- from raglib.llm.base_client import BaseLLMClient
14
- from raglib.schemas import Document, GenerationResult
15
-
16
- logger = logging.getLogger(__name__)
17
-
18
- __all__ = ["EvalSample", "EvalReport", "evaluate", "retrieval_metrics"]
19
-
20
-
21
- @dataclass
22
- class EvalSample:
23
- """Per-question evaluation result."""
24
-
25
- question: str
26
- answer: str
27
- metrics: Dict[str, float] = field(default_factory=dict)
28
- retrieved_ids: List[str] = field(default_factory=list)
29
- error: Optional[str] = None
30
-
31
-
32
- @dataclass
33
- class EvalReport:
34
- """Aggregate evaluation report."""
35
-
36
- samples: List[EvalSample]
37
- summary: Dict[str, float]
38
-
39
- def __str__(self) -> str:
40
- """Readable summary table."""
41
-
42
- lines = [f"{name:<22} {value:.3f}" for name, value in sorted(self.summary.items())]
43
- return "RAG evaluation\n" + "\n".join(lines)
44
-
45
-
46
- def _matches(doc: Document, relevant: Sequence[str]) -> bool:
47
- """A retrieved chunk matches a gold id if ids are equal or the chunk came from that parent/file."""
48
-
49
- candidates = {doc.id, str(doc.metadata.get("parent_id", "")), str(doc.metadata.get("file", "")), doc.source}
50
- return any(item and (item in candidates or doc.id.startswith(f"{item}_chunk_")) for item in relevant)
51
-
52
-
53
- def retrieval_metrics(sources: Sequence[Document], relevant: Sequence[str], k: int) -> Dict[str, float]:
54
- """hit_rate@k, MRR@k, recall@k and nDCG@k against gold document/chunk ids."""
55
-
56
- top = list(sources)[:k]
57
- hits = [_matches(doc, relevant) for doc in top]
58
- first = next((index for index, hit in enumerate(hits, start=1) if hit), None)
59
- covered = sum(1 for item in relevant if any(_matches(doc, [item]) for doc in top))
60
- dcg = sum(1.0 / math.log2(index + 1) for index, hit in enumerate(hits, start=1) if hit)
61
- ideal = sum(1.0 / math.log2(index + 1) for index in range(1, min(len(relevant), k) + 1))
62
- return {
63
- f"hit_rate@{k}": 1.0 if first else 0.0,
64
- f"mrr@{k}": 1.0 / first if first else 0.0,
65
- f"recall@{k}": covered / len(relevant) if relevant else 0.0,
66
- f"ndcg@{k}": dcg / ideal if ideal else 0.0,
67
- }
68
-
69
-
70
- def _judge(judge: BaseLLMClient, instruction: str) -> Optional[float]:
71
- """Ask the judge for a 0..1 score."""
72
-
73
- data = parse_json(
74
- judge.complete(
75
- "You are an evaluation judge for a retrieval-augmented QA system.\n"
76
- f"{instruction}\n"
77
- 'Reply with JSON only: {"score": <number between 0 and 1>, "reason": "<short>"}'
78
- )
79
- )
80
- try:
81
- score = float(data.get("score")) if isinstance(data, dict) else None
82
- except (TypeError, ValueError):
83
- return None
84
- return None if score is None else max(0.0, min(1.0, score))
85
-
86
-
87
- def _answer_metrics(judge: BaseLLMClient, question: str, result: GenerationResult, reference: Optional[str]) -> Dict[str, float]:
88
- """LLM-judged faithfulness, answer relevance, context precision and (with a reference) correctness."""
89
-
90
- context = "\n\n".join(f"[{i}] {doc.content[:800]}" for i, doc in enumerate(result.sources[:8], start=1)) or "(no context)"
91
- metrics: Dict[str, float] = {}
92
- checks = {
93
- "faithfulness": f"Context:\n{context}\n\nAnswer:\n{result.answer}\n\n"
94
- "Score the fraction of factual claims in the answer that are supported by the context.",
95
- "answer_relevance": f"Question: {question}\n\nAnswer:\n{result.answer}\n\n"
96
- "Score how directly and completely the answer addresses the question.",
97
- "context_precision": f"Question: {question}\n\nContext:\n{context}\n\n"
98
- "Score the fraction of context passages that are relevant to the question.",
99
- }
100
- if reference:
101
- checks["correctness"] = (
102
- f"Question: {question}\n\nReference answer:\n{reference}\n\nCandidate answer:\n{result.answer}\n\n"
103
- "Score how well the candidate matches the facts of the reference answer."
104
- )
105
- for name, instruction in checks.items():
106
- score = _judge(judge, instruction)
107
- if score is not None:
108
- metrics[name] = score
109
- return metrics
110
-
111
-
112
- def evaluate(
113
- rag: Any,
114
- dataset: Sequence[Dict[str, Any]],
115
- judge_llm: Optional[BaseLLMClient] = None,
116
- k: int = 5,
117
- max_workers: int = 4,
118
- ) -> EvalReport:
119
- """Run every question through ``rag`` and score it.
120
-
121
- Each dataset row: ``{"question": str, "relevant_ids": [...] (optional), "reference": str (optional)}``.
122
- Retrieval metrics need ``relevant_ids`` (chunk ids, parent document ids, or file paths).
123
- Answer-quality metrics need ``judge_llm`` (use a strong model, ideally different from the generator).
124
- """
125
-
126
- def run_one(row: Dict[str, Any]) -> EvalSample:
127
- question = str(row["question"])
128
- try:
129
- result = rag.query(question)
130
- except Exception as exc: # noqa: BLE001
131
- return EvalSample(question=question, answer="", error=f"{type(exc).__name__}: {exc}")
132
- sample = EvalSample(question=question, answer=result.answer, retrieved_ids=[doc.id for doc in result.sources])
133
- relevant = row.get("relevant_ids") or []
134
- if relevant:
135
- sample.metrics.update(retrieval_metrics(result.sources, relevant, k))
136
- if judge_llm is not None:
137
- sample.metrics.update(_answer_metrics(judge_llm, question, result, row.get("reference")))
138
- sample.metrics["latency_ms"] = float(result.usage.get("latency_ms", 0.0))
139
- return sample
140
-
141
- if max_workers <= 1 or len(dataset) <= 1:
142
- samples = [run_one(row) for row in dataset]
143
- else:
144
- with ThreadPoolExecutor(max_workers=max_workers) as pool:
145
- samples = list(pool.map(run_one, dataset))
146
-
147
- names = sorted({name for sample in samples for name in sample.metrics})
148
- summary = {
149
- name: statistics.fmean(sample.metrics[name] for sample in samples if name in sample.metrics) for name in names
150
- }
151
- summary["errors"] = float(sum(1 for sample in samples if sample.error))
152
- return EvalReport(samples=samples, summary=summary)
1
+ """Evaluation for RAG pipelines: retrieval metrics + LLM-judged answer quality."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import logging
6
+ import math
7
+ import statistics
8
+ from dataclasses import dataclass, field
9
+ from typing import Any, Dict, List, Optional, Sequence
10
+
11
+ from raglib.core.concurrency import parallel_map
12
+ from raglib.core.parsing import parse_json
13
+ from raglib.llm.base_client import BaseLLMClient
14
+ from raglib.schemas import Document, GenerationResult
15
+
16
+ logger = logging.getLogger(__name__)
17
+
18
+ __all__ = ["EvalSample", "EvalReport", "evaluate", "retrieval_metrics"]
19
+
20
+
21
+ @dataclass
22
+ class EvalSample:
23
+ """Per-question evaluation result."""
24
+
25
+ question: str
26
+ answer: str
27
+ metrics: Dict[str, float] = field(default_factory=dict)
28
+ retrieved_ids: List[str] = field(default_factory=list)
29
+ error: Optional[str] = None
30
+
31
+
32
+ @dataclass
33
+ class EvalReport:
34
+ """Aggregate evaluation report."""
35
+
36
+ samples: List[EvalSample]
37
+ summary: Dict[str, float]
38
+
39
+ def __str__(self) -> str:
40
+ """Readable summary table."""
41
+
42
+ lines = [f"{name:<22} {value:.3f}" for name, value in sorted(self.summary.items())]
43
+ return "RAG evaluation\n" + "\n".join(lines)
44
+
45
+
46
+ def _matches(doc: Document, relevant: Sequence[str]) -> bool:
47
+ """A retrieved chunk matches a gold id if ids are equal or the chunk came from that parent/file."""
48
+
49
+ candidates = {doc.id, str(doc.metadata.get("parent_id", "")), str(doc.metadata.get("file", "")), doc.source}
50
+ return any(item and (item in candidates or doc.id.startswith(f"{item}_chunk_")) for item in relevant)
51
+
52
+
53
+ def retrieval_metrics(sources: Sequence[Document], relevant: Sequence[str], k: int) -> Dict[str, float]:
54
+ """hit_rate@k, MRR@k, recall@k and nDCG@k against gold document/chunk ids."""
55
+
56
+ top = list(sources)[:k]
57
+ hits = [_matches(doc, relevant) for doc in top]
58
+ first = next((index for index, hit in enumerate(hits, start=1) if hit), None)
59
+ covered = sum(1 for item in relevant if any(_matches(doc, [item]) for doc in top))
60
+ dcg = sum(1.0 / math.log2(index + 1) for index, hit in enumerate(hits, start=1) if hit)
61
+ ideal = sum(1.0 / math.log2(index + 1) for index in range(1, min(len(relevant), k) + 1))
62
+ return {
63
+ f"hit_rate@{k}": 1.0 if first else 0.0,
64
+ f"mrr@{k}": 1.0 / first if first else 0.0,
65
+ f"recall@{k}": covered / len(relevant) if relevant else 0.0,
66
+ f"ndcg@{k}": dcg / ideal if ideal else 0.0,
67
+ }
68
+
69
+
70
+ def _judge(judge: BaseLLMClient, instruction: str) -> Optional[float]:
71
+ """Ask the judge for a 0..1 score."""
72
+
73
+ data = parse_json(
74
+ judge.complete(
75
+ "You are an evaluation judge for a retrieval-augmented QA system.\n"
76
+ f"{instruction}\n"
77
+ 'Reply with JSON only: {"score": <number between 0 and 1>, "reason": "<short>"}'
78
+ )
79
+ )
80
+ try:
81
+ score = float(data.get("score")) if isinstance(data, dict) else None
82
+ except (TypeError, ValueError):
83
+ return None
84
+ return None if score is None else max(0.0, min(1.0, score))
85
+
86
+
87
+ def _answer_metrics(judge: BaseLLMClient, question: str, result: GenerationResult, reference: Optional[str]) -> Dict[str, float]:
88
+ """LLM-judged faithfulness, answer relevance, context precision and (with a reference) correctness."""
89
+
90
+ context = "\n\n".join(f"[{i}] {doc.content[:800]}" for i, doc in enumerate(result.sources[:8], start=1)) or "(no context)"
91
+ metrics: Dict[str, float] = {}
92
+ checks = {
93
+ "faithfulness": f"Context:\n{context}\n\nAnswer:\n{result.answer}\n\n"
94
+ "Score the fraction of factual claims in the answer that are supported by the context.",
95
+ "answer_relevance": f"Question: {question}\n\nAnswer:\n{result.answer}\n\n"
96
+ "Score how directly and completely the answer addresses the question.",
97
+ "context_precision": f"Question: {question}\n\nContext:\n{context}\n\n"
98
+ "Score the fraction of context passages that are relevant to the question.",
99
+ }
100
+ if reference:
101
+ checks["correctness"] = (
102
+ f"Question: {question}\n\nReference answer:\n{reference}\n\nCandidate answer:\n{result.answer}\n\n"
103
+ "Score how well the candidate matches the facts of the reference answer."
104
+ )
105
+ for name, instruction in checks.items():
106
+ score = _judge(judge, instruction)
107
+ if score is not None:
108
+ metrics[name] = score
109
+ return metrics
110
+
111
+
112
+ def evaluate(
113
+ rag: Any,
114
+ dataset: Sequence[Dict[str, Any]],
115
+ judge_llm: Optional[BaseLLMClient] = None,
116
+ k: int = 5,
117
+ max_workers: int = 4,
118
+ ) -> EvalReport:
119
+ """Run every question through ``rag`` and score it.
120
+
121
+ Each dataset row: ``{"question": str, "relevant_ids": [...] (optional), "reference": str (optional)}``.
122
+ Retrieval metrics need ``relevant_ids`` (chunk ids, parent document ids, or file paths).
123
+ Answer-quality metrics need ``judge_llm`` (use a strong model, ideally different from the generator).
124
+ """
125
+
126
+ def run_one(row: Dict[str, Any]) -> EvalSample:
127
+ question = str(row["question"])
128
+ try:
129
+ result = rag.query(question)
130
+ except Exception as exc: # noqa: BLE001
131
+ return EvalSample(question=question, answer="", error=f"{type(exc).__name__}: {exc}")
132
+ sample = EvalSample(question=question, answer=result.answer, retrieved_ids=[doc.id for doc in result.sources])
133
+ relevant = row.get("relevant_ids") or []
134
+ if relevant:
135
+ sample.metrics.update(retrieval_metrics(result.sources, relevant, k))
136
+ if judge_llm is not None:
137
+ sample.metrics.update(_answer_metrics(judge_llm, question, result, row.get("reference")))
138
+ sample.metrics["latency_ms"] = float(result.usage.get("latency_ms", 0.0))
139
+ return sample
140
+
141
+ samples = parallel_map(run_one, dataset, max_workers)
142
+
143
+ names = sorted({name for sample in samples for name in sample.metrics})
144
+ summary = {
145
+ name: statistics.fmean(sample.metrics[name] for sample in samples if name in sample.metrics) for name in names
146
+ }
147
+ summary["errors"] = float(sum(1 for sample in samples if sample.error))
148
+ return EvalReport(samples=samples, summary=summary)
@@ -4,9 +4,9 @@ from __future__ import annotations
4
4
 
5
5
  import hashlib
6
6
  import logging
7
- from concurrent.futures import ThreadPoolExecutor
8
7
  from typing import Any, Dict, List, Optional, Sequence
9
8
 
9
+ from raglib.core.concurrency import parallel_map
10
10
  from raglib.embedding.base_embedding import BaseEmbedding
11
11
  from raglib.graphrag.schemas import Community
12
12
  from raglib.graphrag.store.base import BaseGraphStore
@@ -144,12 +144,7 @@ class CommunityReporter:
144
144
  todo = [c for c in todo if len(c.entity_ids) >= self.min_llm_report_size]
145
145
  if todo:
146
146
  logger.info("Generating %d community reports (%d reused)", len(todo), len(communities) - len(todo))
147
- if self.max_workers == 1 or len(todo) == 1:
148
- for community in todo:
149
- self._report_one(community, store)
150
- else:
151
- with ThreadPoolExecutor(max_workers=min(self.max_workers, len(todo))) as pool:
152
- list(pool.map(lambda c: self._report_one(c, store), todo))
147
+ parallel_map(lambda c: self._report_one(c, store), todo, self.max_workers)
153
148
 
154
149
  needs_embedding = [c for c in communities if c.summary and c.embedding is None]
155
150
  if self.embedding is not None and needs_embedding:
@@ -5,9 +5,9 @@ from __future__ import annotations
5
5
  import hashlib
6
6
  import logging
7
7
  import threading
8
- from concurrent.futures import ThreadPoolExecutor
9
8
  from typing import Any, Dict, List, Optional, Sequence
10
9
 
10
+ from raglib.core.concurrency import parallel_map
11
11
  from raglib.graphrag.schemas import Entity, ExtractionResult, Relation, normalize_entity_key
12
12
  from raglib.llm.base_client import BaseLLMClient
13
13
  from raglib.schemas import Document
@@ -57,10 +57,7 @@ class GraphExtractor:
57
57
 
58
58
  if not chunks:
59
59
  return {}
60
- if self.max_workers == 1 or len(chunks) == 1:
61
- return {chunk.id: self.extract_one(chunk) for chunk in chunks}
62
- with ThreadPoolExecutor(max_workers=min(self.max_workers, len(chunks))) as pool:
63
- results = list(pool.map(self.extract_one, chunks))
60
+ results = parallel_map(self.extract_one, chunks, self.max_workers)
64
61
  return {chunk.id: result for chunk, result in zip(chunks, results)}
65
62
 
66
63
  def extract_one(self, chunk: Document) -> ExtractionResult: