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.
- {raglib_py-2.0.1 → raglib_py-2.0.3}/PKG-INFO +1 -1
- {raglib_py-2.0.1 → raglib_py-2.0.3}/pyproject.toml +1 -1
- {raglib_py-2.0.1 → raglib_py-2.0.3}/raglib/__init__.py +1 -1
- {raglib_py-2.0.1 → raglib_py-2.0.3}/raglib/components/hybrid_retriever.py +6 -6
- {raglib_py-2.0.1 → raglib_py-2.0.3}/raglib/components/multi_query_retriever.py +2 -3
- {raglib_py-2.0.1 → raglib_py-2.0.3}/raglib/core/concurrency.py +103 -74
- {raglib_py-2.0.1 → raglib_py-2.0.3}/raglib/embedding/cached_embedding.py +3 -7
- {raglib_py-2.0.1 → raglib_py-2.0.3}/raglib/eval/__init__.py +148 -152
- {raglib_py-2.0.1 → raglib_py-2.0.3}/raglib/graphrag/communities.py +2 -7
- {raglib_py-2.0.1 → raglib_py-2.0.3}/raglib/graphrag/extractor.py +2 -5
- {raglib_py-2.0.1 → raglib_py-2.0.3}/raglib/graphrag/search.py +2 -6
- {raglib_py-2.0.1 → raglib_py-2.0.3}/raglib/visualize.py +2 -2
- raglib_py-2.0.3/site/README.md +18 -0
- raglib_py-2.0.3/site/node_modules/@babel/code-frame/LICENSE +22 -0
- raglib_py-2.0.3/site/node_modules/@babel/code-frame/README.md +19 -0
- raglib_py-2.0.3/site/node_modules/@babel/compat-data/LICENSE +22 -0
- raglib_py-2.0.3/site/node_modules/@babel/compat-data/README.md +19 -0
- raglib_py-2.0.3/site/node_modules/@babel/core/LICENSE +22 -0
- raglib_py-2.0.3/site/node_modules/@babel/core/README.md +19 -0
- raglib_py-2.0.3/site/node_modules/@babel/generator/LICENSE +22 -0
- raglib_py-2.0.3/site/node_modules/@babel/generator/README.md +19 -0
- raglib_py-2.0.3/site/node_modules/@babel/helper-compilation-targets/LICENSE +22 -0
- raglib_py-2.0.3/site/node_modules/@babel/helper-compilation-targets/README.md +19 -0
- raglib_py-2.0.3/site/node_modules/@babel/helper-globals/LICENSE +22 -0
- raglib_py-2.0.3/site/node_modules/@babel/helper-globals/README.md +19 -0
- raglib_py-2.0.3/site/node_modules/@babel/helper-module-imports/LICENSE +22 -0
- raglib_py-2.0.3/site/node_modules/@babel/helper-module-imports/README.md +19 -0
- raglib_py-2.0.3/site/node_modules/@babel/helper-module-transforms/LICENSE +22 -0
- raglib_py-2.0.3/site/node_modules/@babel/helper-module-transforms/README.md +19 -0
- raglib_py-2.0.3/site/node_modules/@babel/helper-plugin-utils/LICENSE +22 -0
- raglib_py-2.0.3/site/node_modules/@babel/helper-plugin-utils/README.md +19 -0
- raglib_py-2.0.3/site/node_modules/@babel/helper-string-parser/LICENSE +22 -0
- raglib_py-2.0.3/site/node_modules/@babel/helper-string-parser/README.md +19 -0
- raglib_py-2.0.3/site/node_modules/@babel/helper-validator-identifier/LICENSE +22 -0
- raglib_py-2.0.3/site/node_modules/@babel/helper-validator-identifier/README.md +19 -0
- raglib_py-2.0.3/site/node_modules/@babel/helper-validator-option/LICENSE +22 -0
- raglib_py-2.0.3/site/node_modules/@babel/helper-validator-option/README.md +19 -0
- raglib_py-2.0.3/site/node_modules/@babel/helpers/LICENSE +23 -0
- raglib_py-2.0.3/site/node_modules/@babel/helpers/README.md +19 -0
- raglib_py-2.0.3/site/node_modules/@babel/parser/LICENSE +19 -0
- raglib_py-2.0.3/site/node_modules/@babel/parser/README.md +19 -0
- raglib_py-2.0.3/site/node_modules/@babel/plugin-transform-react-jsx-self/LICENSE +22 -0
- raglib_py-2.0.3/site/node_modules/@babel/plugin-transform-react-jsx-self/README.md +19 -0
- raglib_py-2.0.3/site/node_modules/@babel/plugin-transform-react-jsx-source/LICENSE +22 -0
- raglib_py-2.0.3/site/node_modules/@babel/plugin-transform-react-jsx-source/README.md +19 -0
- raglib_py-2.0.3/site/node_modules/@babel/template/LICENSE +22 -0
- raglib_py-2.0.3/site/node_modules/@babel/template/README.md +19 -0
- raglib_py-2.0.3/site/node_modules/@babel/traverse/LICENSE +22 -0
- raglib_py-2.0.3/site/node_modules/@babel/traverse/README.md +19 -0
- raglib_py-2.0.3/site/node_modules/@babel/types/LICENSE +22 -0
- raglib_py-2.0.3/site/node_modules/@babel/types/README.md +19 -0
- raglib_py-2.0.3/site/node_modules/@esbuild/win32-x64/README.md +3 -0
- raglib_py-2.0.3/site/node_modules/@jridgewell/gen-mapping/LICENSE +19 -0
- raglib_py-2.0.3/site/node_modules/@jridgewell/gen-mapping/README.md +227 -0
- raglib_py-2.0.3/site/node_modules/@jridgewell/remapping/LICENSE +19 -0
- raglib_py-2.0.3/site/node_modules/@jridgewell/remapping/README.md +218 -0
- raglib_py-2.0.3/site/node_modules/@jridgewell/resolve-uri/LICENSE +19 -0
- raglib_py-2.0.3/site/node_modules/@jridgewell/resolve-uri/README.md +40 -0
- raglib_py-2.0.3/site/node_modules/@jridgewell/sourcemap-codec/LICENSE +19 -0
- raglib_py-2.0.3/site/node_modules/@jridgewell/sourcemap-codec/README.md +264 -0
- raglib_py-2.0.3/site/node_modules/@jridgewell/trace-mapping/LICENSE +19 -0
- raglib_py-2.0.3/site/node_modules/@jridgewell/trace-mapping/README.md +348 -0
- raglib_py-2.0.3/site/node_modules/@rolldown/pluginutils/LICENSE +25 -0
- raglib_py-2.0.3/site/node_modules/@rollup/rollup-win32-x64-gnu/README.md +3 -0
- raglib_py-2.0.3/site/node_modules/@rollup/rollup-win32-x64-msvc/README.md +3 -0
- raglib_py-2.0.3/site/node_modules/@types/babel__core/LICENSE +21 -0
- raglib_py-2.0.3/site/node_modules/@types/babel__core/README.md +15 -0
- raglib_py-2.0.3/site/node_modules/@types/babel__generator/LICENSE +21 -0
- raglib_py-2.0.3/site/node_modules/@types/babel__generator/README.md +15 -0
- raglib_py-2.0.3/site/node_modules/@types/babel__template/LICENSE +21 -0
- raglib_py-2.0.3/site/node_modules/@types/babel__template/README.md +15 -0
- raglib_py-2.0.3/site/node_modules/@types/babel__traverse/LICENSE +21 -0
- raglib_py-2.0.3/site/node_modules/@types/babel__traverse/README.md +15 -0
- raglib_py-2.0.3/site/node_modules/@types/estree/LICENSE +21 -0
- raglib_py-2.0.3/site/node_modules/@types/estree/README.md +15 -0
- raglib_py-2.0.3/site/node_modules/@types/prop-types/LICENSE +21 -0
- raglib_py-2.0.3/site/node_modules/@types/prop-types/README.md +15 -0
- raglib_py-2.0.3/site/node_modules/@types/react/LICENSE +21 -0
- raglib_py-2.0.3/site/node_modules/@types/react/README.md +15 -0
- raglib_py-2.0.3/site/node_modules/@types/react-dom/LICENSE +21 -0
- raglib_py-2.0.3/site/node_modules/@types/react-dom/README.md +15 -0
- raglib_py-2.0.3/site/node_modules/@vitejs/plugin-react/LICENSE +21 -0
- raglib_py-2.0.3/site/node_modules/@vitejs/plugin-react/README.md +142 -0
- raglib_py-2.0.3/site/node_modules/baseline-browser-mapping/README.md +545 -0
- raglib_py-2.0.3/site/node_modules/browserslist/LICENSE +20 -0
- raglib_py-2.0.3/site/node_modules/browserslist/README.md +66 -0
- raglib_py-2.0.3/site/node_modules/caniuse-lite/LICENSE +395 -0
- raglib_py-2.0.3/site/node_modules/caniuse-lite/README.md +3 -0
- raglib_py-2.0.3/site/node_modules/convert-source-map/LICENSE +23 -0
- raglib_py-2.0.3/site/node_modules/convert-source-map/README.md +206 -0
- raglib_py-2.0.3/site/node_modules/csstype/LICENSE +19 -0
- raglib_py-2.0.3/site/node_modules/csstype/README.md +291 -0
- raglib_py-2.0.3/site/node_modules/debug/LICENSE +20 -0
- raglib_py-2.0.3/site/node_modules/debug/README.md +481 -0
- raglib_py-2.0.3/site/node_modules/electron-to-chromium/LICENSE +5 -0
- raglib_py-2.0.3/site/node_modules/electron-to-chromium/README.md +186 -0
- raglib_py-2.0.3/site/node_modules/esbuild/README.md +3 -0
- raglib_py-2.0.3/site/node_modules/gensync/LICENSE +7 -0
- raglib_py-2.0.3/site/node_modules/gensync/README.md +196 -0
- raglib_py-2.0.3/site/node_modules/js-tokens/LICENSE +21 -0
- raglib_py-2.0.3/site/node_modules/js-tokens/README.md +240 -0
- raglib_py-2.0.3/site/node_modules/jsesc/README.md +422 -0
- raglib_py-2.0.3/site/node_modules/json5/README.md +282 -0
- raglib_py-2.0.3/site/node_modules/loose-envify/LICENSE +21 -0
- raglib_py-2.0.3/site/node_modules/loose-envify/README.md +45 -0
- raglib_py-2.0.3/site/node_modules/lru-cache/LICENSE +15 -0
- raglib_py-2.0.3/site/node_modules/lru-cache/README.md +166 -0
- raglib_py-2.0.3/site/node_modules/nanoid/LICENSE +20 -0
- raglib_py-2.0.3/site/node_modules/nanoid/README.md +39 -0
- raglib_py-2.0.3/site/node_modules/node-releases/LICENSE +21 -0
- raglib_py-2.0.3/site/node_modules/node-releases/README.md +32 -0
- raglib_py-2.0.3/site/node_modules/picocolors/LICENSE +15 -0
- raglib_py-2.0.3/site/node_modules/picocolors/README.md +21 -0
- raglib_py-2.0.3/site/node_modules/postcss/LICENSE +20 -0
- raglib_py-2.0.3/site/node_modules/postcss/README.md +27 -0
- raglib_py-2.0.3/site/node_modules/react/LICENSE +21 -0
- raglib_py-2.0.3/site/node_modules/react/README.md +37 -0
- raglib_py-2.0.3/site/node_modules/react-dom/LICENSE +21 -0
- raglib_py-2.0.3/site/node_modules/react-dom/README.md +60 -0
- raglib_py-2.0.3/site/node_modules/react-refresh/LICENSE +21 -0
- raglib_py-2.0.3/site/node_modules/react-refresh/README.md +5 -0
- raglib_py-2.0.3/site/node_modules/rollup/README.md +134 -0
- raglib_py-2.0.3/site/node_modules/scheduler/LICENSE +21 -0
- raglib_py-2.0.3/site/node_modules/scheduler/README.md +9 -0
- raglib_py-2.0.3/site/node_modules/semver/LICENSE +15 -0
- raglib_py-2.0.3/site/node_modules/semver/README.md +443 -0
- raglib_py-2.0.3/site/node_modules/source-map-js/LICENSE +28 -0
- raglib_py-2.0.3/site/node_modules/source-map-js/README.md +765 -0
- raglib_py-2.0.3/site/node_modules/typescript/README.md +50 -0
- raglib_py-2.0.3/site/node_modules/update-browserslist-db/LICENSE +20 -0
- raglib_py-2.0.3/site/node_modules/update-browserslist-db/README.md +41 -0
- raglib_py-2.0.3/site/node_modules/vite/README.md +20 -0
- raglib_py-2.0.3/site/node_modules/yallist/LICENSE +15 -0
- raglib_py-2.0.3/site/node_modules/yallist/README.md +204 -0
- {raglib_py-2.0.1 → raglib_py-2.0.3}/.gitignore +0 -0
- {raglib_py-2.0.1 → raglib_py-2.0.3}/LICENSE +0 -0
- {raglib_py-2.0.1 → raglib_py-2.0.3}/README.md +0 -0
- {raglib_py-2.0.1 → raglib_py-2.0.3}/raglib/__main__.py +0 -0
- {raglib_py-2.0.1 → raglib_py-2.0.3}/raglib/cli.py +0 -0
- {raglib_py-2.0.1 → raglib_py-2.0.3}/raglib/components/__init__.py +0 -0
- {raglib_py-2.0.1 → raglib_py-2.0.3}/raglib/components/bm25.py +0 -0
- {raglib_py-2.0.1 → raglib_py-2.0.3}/raglib/components/context_reducer.py +0 -0
- {raglib_py-2.0.1 → raglib_py-2.0.3}/raglib/components/decision.py +0 -0
- {raglib_py-2.0.1 → raglib_py-2.0.3}/raglib/components/deduplicator.py +0 -0
- {raglib_py-2.0.1 → raglib_py-2.0.3}/raglib/components/evaluator.py +0 -0
- {raglib_py-2.0.1 → raglib_py-2.0.3}/raglib/components/generator.py +0 -0
- {raglib_py-2.0.1 → raglib_py-2.0.3}/raglib/components/grader.py +0 -0
- {raglib_py-2.0.1 → raglib_py-2.0.3}/raglib/components/memory.py +0 -0
- {raglib_py-2.0.1 → raglib_py-2.0.3}/raglib/components/multi_hop_retriever.py +0 -0
- {raglib_py-2.0.1 → raglib_py-2.0.3}/raglib/components/planner.py +0 -0
- {raglib_py-2.0.1 → raglib_py-2.0.3}/raglib/components/query_expander.py +0 -0
- {raglib_py-2.0.1 → raglib_py-2.0.3}/raglib/components/query_rewriter.py +0 -0
- {raglib_py-2.0.1 → raglib_py-2.0.3}/raglib/components/refiner.py +0 -0
- {raglib_py-2.0.1 → raglib_py-2.0.3}/raglib/components/reflection.py +0 -0
- {raglib_py-2.0.1 → raglib_py-2.0.3}/raglib/components/reranker.py +0 -0
- {raglib_py-2.0.1 → raglib_py-2.0.3}/raglib/components/retriever.py +0 -0
- {raglib_py-2.0.1 → raglib_py-2.0.3}/raglib/components/router_retriever.py +0 -0
- {raglib_py-2.0.1 → raglib_py-2.0.3}/raglib/components/tools.py +0 -0
- {raglib_py-2.0.1 → raglib_py-2.0.3}/raglib/components/web_retriever.py +0 -0
- {raglib_py-2.0.1 → raglib_py-2.0.3}/raglib/constants.py +0 -0
- {raglib_py-2.0.1 → raglib_py-2.0.3}/raglib/core/__init__.py +0 -0
- {raglib_py-2.0.1 → raglib_py-2.0.3}/raglib/core/base.py +0 -0
- {raglib_py-2.0.1 → raglib_py-2.0.3}/raglib/core/fusion.py +0 -0
- {raglib_py-2.0.1 → raglib_py-2.0.3}/raglib/core/intents.py +0 -0
- {raglib_py-2.0.1 → raglib_py-2.0.3}/raglib/core/parsing.py +0 -0
- {raglib_py-2.0.1 → raglib_py-2.0.3}/raglib/core/text.py +0 -0
- {raglib_py-2.0.1 → raglib_py-2.0.3}/raglib/core/tracing.py +0 -0
- {raglib_py-2.0.1 → raglib_py-2.0.3}/raglib/embedding/__init__.py +0 -0
- {raglib_py-2.0.1 → raglib_py-2.0.3}/raglib/embedding/base_embedding.py +0 -0
- {raglib_py-2.0.1 → raglib_py-2.0.3}/raglib/embedding/embedding_factory.py +0 -0
- {raglib_py-2.0.1 → raglib_py-2.0.3}/raglib/embedding/google_embedding.py +0 -0
- {raglib_py-2.0.1 → raglib_py-2.0.3}/raglib/embedding/huggingface_embedding.py +0 -0
- {raglib_py-2.0.1 → raglib_py-2.0.3}/raglib/embedding/mock_embedding.py +0 -0
- {raglib_py-2.0.1 → raglib_py-2.0.3}/raglib/embedding/ollama_embedding.py +0 -0
- {raglib_py-2.0.1 → raglib_py-2.0.3}/raglib/embedding/openai_embedding.py +0 -0
- {raglib_py-2.0.1 → raglib_py-2.0.3}/raglib/facade.py +0 -0
- {raglib_py-2.0.1 → raglib_py-2.0.3}/raglib/graph_context/__init__.py +0 -0
- {raglib_py-2.0.1 → raglib_py-2.0.3}/raglib/graph_context/engine.py +0 -0
- {raglib_py-2.0.1 → raglib_py-2.0.3}/raglib/graph_context/schemas.py +0 -0
- {raglib_py-2.0.1 → raglib_py-2.0.3}/raglib/graphrag/__init__.py +0 -0
- {raglib_py-2.0.1 → raglib_py-2.0.3}/raglib/graphrag/indexer.py +0 -0
- {raglib_py-2.0.1 → raglib_py-2.0.3}/raglib/graphrag/schemas.py +0 -0
- {raglib_py-2.0.1 → raglib_py-2.0.3}/raglib/graphrag/store/__init__.py +0 -0
- {raglib_py-2.0.1 → raglib_py-2.0.3}/raglib/graphrag/store/base.py +0 -0
- {raglib_py-2.0.1 → raglib_py-2.0.3}/raglib/graphrag/store/neo4j_store.py +0 -0
- {raglib_py-2.0.1 → raglib_py-2.0.3}/raglib/graphrag/store/networkx_store.py +0 -0
- {raglib_py-2.0.1 → raglib_py-2.0.3}/raglib/llm/__init__.py +0 -0
- {raglib_py-2.0.1 → raglib_py-2.0.3}/raglib/llm/base_client.py +0 -0
- {raglib_py-2.0.1 → raglib_py-2.0.3}/raglib/llm/constants.py +0 -0
- {raglib_py-2.0.1 → raglib_py-2.0.3}/raglib/llm/langchain_adapter.py +0 -0
- {raglib_py-2.0.1 → raglib_py-2.0.3}/raglib/llm/mock_client.py +0 -0
- {raglib_py-2.0.1 → raglib_py-2.0.3}/raglib/llm/provider_detector.py +0 -0
- {raglib_py-2.0.1 → raglib_py-2.0.3}/raglib/llm/providers.py +0 -0
- {raglib_py-2.0.1 → raglib_py-2.0.3}/raglib/llm/resilience.py +0 -0
- {raglib_py-2.0.1 → raglib_py-2.0.3}/raglib/loaders/__init__.py +0 -0
- {raglib_py-2.0.1 → raglib_py-2.0.3}/raglib/loaders/chunk_splitter.py +0 -0
- {raglib_py-2.0.1 → raglib_py-2.0.3}/raglib/loaders/document_loader.py +0 -0
- {raglib_py-2.0.1 → raglib_py-2.0.3}/raglib/loaders/exceptions.py +0 -0
- {raglib_py-2.0.1 → raglib_py-2.0.3}/raglib/loaders/pdf_loader.py +0 -0
- {raglib_py-2.0.1 → raglib_py-2.0.3}/raglib/loaders/pptx_loader.py +0 -0
- {raglib_py-2.0.1 → raglib_py-2.0.3}/raglib/loaders/text_loader.py +0 -0
- {raglib_py-2.0.1 → raglib_py-2.0.3}/raglib/loaders/web_loader.py +0 -0
- {raglib_py-2.0.1 → raglib_py-2.0.3}/raglib/loaders/word_loader.py +0 -0
- {raglib_py-2.0.1 → raglib_py-2.0.3}/raglib/preprocessing/__init__.py +0 -0
- {raglib_py-2.0.1 → raglib_py-2.0.3}/raglib/preprocessing/chunk_splitter.py +0 -0
- {raglib_py-2.0.1 → raglib_py-2.0.3}/raglib/providers/__init__.py +0 -0
- {raglib_py-2.0.1 → raglib_py-2.0.3}/raglib/providers/base_provider.py +0 -0
- {raglib_py-2.0.1 → raglib_py-2.0.3}/raglib/providers/bing_provider.py +0 -0
- {raglib_py-2.0.1 → raglib_py-2.0.3}/raglib/providers/brave_provider.py +0 -0
- {raglib_py-2.0.1 → raglib_py-2.0.3}/raglib/providers/duckduckgo_provider.py +0 -0
- {raglib_py-2.0.1 → raglib_py-2.0.3}/raglib/providers/exa_provider.py +0 -0
- {raglib_py-2.0.1 → raglib_py-2.0.3}/raglib/providers/factory.py +0 -0
- {raglib_py-2.0.1 → raglib_py-2.0.3}/raglib/providers/google_cse_provider.py +0 -0
- {raglib_py-2.0.1 → raglib_py-2.0.3}/raglib/providers/searxng_provider.py +0 -0
- {raglib_py-2.0.1 → raglib_py-2.0.3}/raglib/providers/serpapi_provider.py +0 -0
- {raglib_py-2.0.1 → raglib_py-2.0.3}/raglib/providers/tavily_provider.py +0 -0
- {raglib_py-2.0.1 → raglib_py-2.0.3}/raglib/quick.py +0 -0
- {raglib_py-2.0.1 → raglib_py-2.0.3}/raglib/rag_types/__init__.py +0 -0
- {raglib_py-2.0.1 → raglib_py-2.0.3}/raglib/rag_types/advanced_rag.py +0 -0
- {raglib_py-2.0.1 → raglib_py-2.0.3}/raglib/rag_types/agentic_rag.py +0 -0
- {raglib_py-2.0.1 → raglib_py-2.0.3}/raglib/rag_types/corrective_rag.py +0 -0
- {raglib_py-2.0.1 → raglib_py-2.0.3}/raglib/rag_types/graph_rag.py +0 -0
- {raglib_py-2.0.1 → raglib_py-2.0.3}/raglib/rag_types/hybrid_rag.py +0 -0
- {raglib_py-2.0.1 → raglib_py-2.0.3}/raglib/rag_types/memory_rag.py +0 -0
- {raglib_py-2.0.1 → raglib_py-2.0.3}/raglib/rag_types/multi_hop_rag.py +0 -0
- {raglib_py-2.0.1 → raglib_py-2.0.3}/raglib/rag_types/multi_query_rag.py +0 -0
- {raglib_py-2.0.1 → raglib_py-2.0.3}/raglib/rag_types/naive_rag.py +0 -0
- {raglib_py-2.0.1 → raglib_py-2.0.3}/raglib/rag_types/routing_rag.py +0 -0
- {raglib_py-2.0.1 → raglib_py-2.0.3}/raglib/rag_types/self_rag.py +0 -0
- {raglib_py-2.0.1 → raglib_py-2.0.3}/raglib/rag_types/tool_augmented_rag.py +0 -0
- {raglib_py-2.0.1 → raglib_py-2.0.3}/raglib/rag_types/web_rag.py +0 -0
- {raglib_py-2.0.1 → raglib_py-2.0.3}/raglib/schemas.py +0 -0
- {raglib_py-2.0.1 → raglib_py-2.0.3}/raglib/session/__init__.py +0 -0
- {raglib_py-2.0.1 → raglib_py-2.0.3}/raglib/session/interactive.py +0 -0
- {raglib_py-2.0.1 → raglib_py-2.0.3}/raglib/vectorstores/__init__.py +0 -0
- {raglib_py-2.0.1 → raglib_py-2.0.3}/raglib/vectorstores/base_store.py +0 -0
- {raglib_py-2.0.1 → raglib_py-2.0.3}/raglib/vectorstores/chroma_store.py +0 -0
- {raglib_py-2.0.1 → raglib_py-2.0.3}/raglib/vectorstores/factory.py +0 -0
- {raglib_py-2.0.1 → raglib_py-2.0.3}/raglib/vectorstores/in_memory_store.py +0 -0
- {raglib_py-2.0.1 → raglib_py-2.0.3}/raglib/vision/__init__.py +0 -0
- {raglib_py-2.0.1 → raglib_py-2.0.3}/raglib/vision/anthropic_vision.py +0 -0
- {raglib_py-2.0.1 → raglib_py-2.0.3}/raglib/vision/base_vision.py +0 -0
- {raglib_py-2.0.1 → raglib_py-2.0.3}/raglib/vision/google_vision.py +0 -0
- {raglib_py-2.0.1 → raglib_py-2.0.3}/raglib/vision/mock_vision.py +0 -0
- {raglib_py-2.0.1 → raglib_py-2.0.3}/raglib/vision/openai_vision.py +0 -0
- {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.
|
|
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.
|
|
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" }
|
|
@@ -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
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
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
|
-
|
|
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
|
|
6
|
-
|
|
7
|
-
from
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
"""
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
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
|
-
self.
|
|
65
|
-
|
|
66
|
-
self.
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
self._writer_depth
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
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
|
-
|
|
105
|
-
|
|
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
|
|
9
|
-
from
|
|
10
|
-
|
|
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
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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:
|