knowledge-rag 5.0.1__tar.gz → 5.1.0__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.
- {knowledge_rag-5.0.1 → knowledge_rag-5.1.0}/PKG-INFO +13 -10
- {knowledge_rag-5.0.1 → knowledge_rag-5.1.0}/README.md +12 -9
- {knowledge_rag-5.0.1 → knowledge_rag-5.1.0}/config.example.yaml +18 -0
- {knowledge_rag-5.0.1 → knowledge_rag-5.1.0}/mcp_server/__init__.py +1 -1
- {knowledge_rag-5.0.1 → knowledge_rag-5.1.0}/mcp_server/config.py +19 -1
- {knowledge_rag-5.0.1 → knowledge_rag-5.1.0}/mcp_server/data/config.example.yaml +18 -0
- {knowledge_rag-5.0.1 → knowledge_rag-5.1.0}/mcp_server/ingestion.py +94 -9
- {knowledge_rag-5.0.1 → knowledge_rag-5.1.0}/mcp_server/server.py +698 -93
- {knowledge_rag-5.0.1 → knowledge_rag-5.1.0}/pyproject.toml +1 -1
- {knowledge_rag-5.0.1 → knowledge_rag-5.1.0}/skills/maintenance/rag-evaluate-quality/SKILL.md +1 -1
- {knowledge_rag-5.0.1 → knowledge_rag-5.1.0}/.gitignore +0 -0
- {knowledge_rag-5.0.1 → knowledge_rag-5.1.0}/LICENSE +0 -0
- {knowledge_rag-5.0.1 → knowledge_rag-5.1.0}/bench/dashboard/README.md +0 -0
- {knowledge_rag-5.0.1 → knowledge_rag-5.1.0}/mcp_server/assistants.py +0 -0
- {knowledge_rag-5.0.1 → knowledge_rag-5.1.0}/mcp_server/data/cybersecurity.yaml +0 -0
- {knowledge_rag-5.0.1 → knowledge_rag-5.1.0}/mcp_server/data/developer.yaml +0 -0
- {knowledge_rag-5.0.1 → knowledge_rag-5.1.0}/mcp_server/data/general.yaml +0 -0
- {knowledge_rag-5.0.1 → knowledge_rag-5.1.0}/mcp_server/data/multilingual.yaml +0 -0
- {knowledge_rag-5.0.1 → knowledge_rag-5.1.0}/mcp_server/data/research.yaml +0 -0
- {knowledge_rag-5.0.1 → knowledge_rag-5.1.0}/mcp_server/file_transaction.py +0 -0
- {knowledge_rag-5.0.1 → knowledge_rag-5.1.0}/mcp_server/filesystem.py +0 -0
- {knowledge_rag-5.0.1 → knowledge_rag-5.1.0}/mcp_server/fts5_index.py +0 -0
- {knowledge_rag-5.0.1 → knowledge_rag-5.1.0}/mcp_server/guarded.py +0 -0
- {knowledge_rag-5.0.1 → knowledge_rag-5.1.0}/mcp_server/health.py +0 -0
- {knowledge_rag-5.0.1 → knowledge_rag-5.1.0}/mcp_server/instance_lock.py +0 -0
- {knowledge_rag-5.0.1 → knowledge_rag-5.1.0}/mcp_server/logging_config.py +0 -0
- {knowledge_rag-5.0.1 → knowledge_rag-5.1.0}/mcp_server/metrics.py +0 -0
- {knowledge_rag-5.0.1 → knowledge_rag-5.1.0}/mcp_server/pdf_support.py +0 -0
- {knowledge_rag-5.0.1 → knowledge_rag-5.1.0}/mcp_server/preflight.py +0 -0
- {knowledge_rag-5.0.1 → knowledge_rag-5.1.0}/mcp_server/publication.py +0 -0
- {knowledge_rag-5.0.1 → knowledge_rag-5.1.0}/mcp_server/query_router.py +0 -0
- {knowledge_rag-5.0.1 → knowledge_rag-5.1.0}/mcp_server/ratelimit.py +0 -0
- {knowledge_rag-5.0.1 → knowledge_rag-5.1.0}/mcp_server/search_candidates.py +0 -0
- {knowledge_rag-5.0.1 → knowledge_rag-5.1.0}/mcp_server/search_scope.py +0 -0
- {knowledge_rag-5.0.1 → knowledge_rag-5.1.0}/mcp_server/security.py +0 -0
- {knowledge_rag-5.0.1 → knowledge_rag-5.1.0}/mcp_server/skills_bundle.py +0 -0
- {knowledge_rag-5.0.1 → knowledge_rag-5.1.0}/mcp_server/skills_cli.py +0 -0
- {knowledge_rag-5.0.1 → knowledge_rag-5.1.0}/npm/README.md +0 -0
- {knowledge_rag-5.0.1 → knowledge_rag-5.1.0}/presets/cybersecurity.yaml +0 -0
- {knowledge_rag-5.0.1 → knowledge_rag-5.1.0}/presets/developer.yaml +0 -0
- {knowledge_rag-5.0.1 → knowledge_rag-5.1.0}/presets/general.yaml +0 -0
- {knowledge_rag-5.0.1 → knowledge_rag-5.1.0}/presets/multilingual.yaml +0 -0
- {knowledge_rag-5.0.1 → knowledge_rag-5.1.0}/presets/research.yaml +0 -0
- {knowledge_rag-5.0.1 → knowledge_rag-5.1.0}/requirements.txt +0 -0
- {knowledge_rag-5.0.1 → knowledge_rag-5.1.0}/skills/README.md +0 -0
- {knowledge_rag-5.0.1 → knowledge_rag-5.1.0}/skills/domain/rag-security-first/SKILL.md +0 -0
- {knowledge_rag-5.0.1 → knowledge_rag-5.1.0}/skills/foundation/rag-check-first/SKILL.md +0 -0
- {knowledge_rag-5.0.1 → knowledge_rag-5.1.0}/skills/foundation/rag-cite-sources/SKILL.md +0 -0
- {knowledge_rag-5.0.1 → knowledge_rag-5.1.0}/skills/foundation/rag-onboard-context/SKILL.md +0 -0
- {knowledge_rag-5.0.1 → knowledge_rag-5.1.0}/skills/maintenance/rag-index-decisions/SKILL.md +0 -0
- {knowledge_rag-5.0.1 → knowledge_rag-5.1.0}/skills/workflow/rag-code-review/SKILL.md +0 -0
- {knowledge_rag-5.0.1 → knowledge_rag-5.1.0}/skills/workflow/rag-deep-dive/SKILL.md +0 -0
- {knowledge_rag-5.0.1 → knowledge_rag-5.1.0}/skills/workflow/rag-troubleshoot/SKILL.md +0 -0
- {knowledge_rag-5.0.1 → knowledge_rag-5.1.0}/skills/workflow/rag-web-fallback/SKILL.md +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: knowledge-rag
|
|
3
|
-
Version: 5.0
|
|
3
|
+
Version: 5.1.0
|
|
4
4
|
Summary: Local RAG System for Claude Code — Hybrid search + Cross-encoder Reranking + 13 MCP Tools + 20 Format Parsers. Zero external servers.
|
|
5
5
|
Project-URL: Homepage, https://github.com/lyonzin/knowledge-rag
|
|
6
6
|
Project-URL: Repository, https://github.com/lyonzin/knowledge-rag
|
|
@@ -59,17 +59,20 @@ Description-Content-Type: text/markdown
|
|
|
59
59
|
|
|
60
60
|
**knowledge-rag** is a local retrieval-augmented generation (RAG) server for the Model Context Protocol (MCP). It indexes the documents and code on your machine and gives Claude Code, Cursor, VS Code and other MCP clients 13 tools to search them, using hybrid search (BM25 keywords plus vector similarity) with cross-encoder reranking on by default. Everything runs in one Python process with embedded ChromaDB and FastEmbed ONNX models: no Docker, no database server, no API key. Indexing and search work offline once the models are cached.
|
|
61
61
|
|
|
62
|
+
<div align="center">
|
|
63
|
+
|
|
64
|
+
[](https://pypi.org/project/knowledge-rag/)
|
|
65
|
+
[](https://www.npmjs.com/package/knowledge-rag)
|
|
66
|
+
[](https://pepy.tech/projects/knowledge-rag)
|
|
67
|
+

|
|
68
|
+

|
|
69
|
+

|
|
70
|
+

|
|
62
71
|
[](https://github.com/lyonzin/knowledge-rag/actions/workflows/security.yml)
|
|
63
72
|
[](https://github.com/lyonzin/knowledge-rag/actions/workflows/quality-gate.yml)
|
|
73
|
+
[](https://glama.ai/mcp/servers/lyonzin/knowledge-rag)
|
|
64
74
|
[](https://bestpractices.coreinfrastructure.org/projects/13864)
|
|
65
|
-
|
|
66
|
-
[](https://pypi.org/project/knowledge-rag/)
|
|
67
|
-
[](https://www.npmjs.com/package/knowledge-rag)
|
|
68
|
-
[](https://pepy.tech/projects/knowledge-rag)<br>
|
|
69
|
-

|
|
70
|
-

|
|
71
|
-

|
|
72
|
-

|
|
75
|
+
</div>
|
|
73
76
|
|
|
74
77
|
- **11.1 ms** median uncached hybrid query on CPU, **6.1 ms** on CUDA: 36 queries over 149 chunks on one Windows host, reranker off ([audit](docs/audit-2026-10-03.md#real-cpu-and-nvidia-workload))
|
|
75
78
|
- **0.03 ms** median for a repeated query served from the cache, same workload ([audit](docs/audit-2026-10-03.md#real-cpu-and-nvidia-workload))
|
|
@@ -410,7 +413,7 @@ All install methods, GPU setup and troubleshooting for each client: [docs/INSTAL
|
|
|
410
413
|
| `evaluate_retrieval` | Reports MRR@5 and Recall@5 for your own query → expected file pairs |
|
|
411
414
|
| `list_documents` | Lists indexed documents, 100 per page by default (up to 200 with `limit`), paged with `offset` |
|
|
412
415
|
| `list_categories` | Lists categories, derived from folder paths, with document counts |
|
|
413
|
-
| `get_index_stats` | Document and chunk counts, embedding model, BM25 status, cache hit rate, watcher status |
|
|
416
|
+
| `get_index_stats` | Document and chunk counts, embedding model, BM25 status, cache hit rate, watcher status, HNSW self-recall probe |
|
|
414
417
|
| `add_document` | Saves text as a file under `documents/` and indexes it |
|
|
415
418
|
| `update_document` | Replaces a document's content and re-indexes it |
|
|
416
419
|
| `remove_document` | Removes a document's chunks from the index, and optionally the file |
|
|
@@ -10,17 +10,20 @@
|
|
|
10
10
|
|
|
11
11
|
**knowledge-rag** is a local retrieval-augmented generation (RAG) server for the Model Context Protocol (MCP). It indexes the documents and code on your machine and gives Claude Code, Cursor, VS Code and other MCP clients 13 tools to search them, using hybrid search (BM25 keywords plus vector similarity) with cross-encoder reranking on by default. Everything runs in one Python process with embedded ChromaDB and FastEmbed ONNX models: no Docker, no database server, no API key. Indexing and search work offline once the models are cached.
|
|
12
12
|
|
|
13
|
+
<div align="center">
|
|
14
|
+
|
|
15
|
+
[](https://pypi.org/project/knowledge-rag/)
|
|
16
|
+
[](https://www.npmjs.com/package/knowledge-rag)
|
|
17
|
+
[](https://pepy.tech/projects/knowledge-rag)
|
|
18
|
+

|
|
19
|
+

|
|
20
|
+

|
|
21
|
+

|
|
13
22
|
[](https://github.com/lyonzin/knowledge-rag/actions/workflows/security.yml)
|
|
14
23
|
[](https://github.com/lyonzin/knowledge-rag/actions/workflows/quality-gate.yml)
|
|
24
|
+
[](https://glama.ai/mcp/servers/lyonzin/knowledge-rag)
|
|
15
25
|
[](https://bestpractices.coreinfrastructure.org/projects/13864)
|
|
16
|
-
|
|
17
|
-
[](https://pypi.org/project/knowledge-rag/)
|
|
18
|
-
[](https://www.npmjs.com/package/knowledge-rag)
|
|
19
|
-
[](https://pepy.tech/projects/knowledge-rag)<br>
|
|
20
|
-

|
|
21
|
-

|
|
22
|
-

|
|
23
|
-

|
|
26
|
+
</div>
|
|
24
27
|
|
|
25
28
|
- **11.1 ms** median uncached hybrid query on CPU, **6.1 ms** on CUDA: 36 queries over 149 chunks on one Windows host, reranker off ([audit](docs/audit-2026-10-03.md#real-cpu-and-nvidia-workload))
|
|
26
29
|
- **0.03 ms** median for a repeated query served from the cache, same workload ([audit](docs/audit-2026-10-03.md#real-cpu-and-nvidia-workload))
|
|
@@ -361,7 +364,7 @@ All install methods, GPU setup and troubleshooting for each client: [docs/INSTAL
|
|
|
361
364
|
| `evaluate_retrieval` | Reports MRR@5 and Recall@5 for your own query → expected file pairs |
|
|
362
365
|
| `list_documents` | Lists indexed documents, 100 per page by default (up to 200 with `limit`), paged with `offset` |
|
|
363
366
|
| `list_categories` | Lists categories, derived from folder paths, with document counts |
|
|
364
|
-
| `get_index_stats` | Document and chunk counts, embedding model, BM25 status, cache hit rate, watcher status |
|
|
367
|
+
| `get_index_stats` | Document and chunk counts, embedding model, BM25 status, cache hit rate, watcher status, HNSW self-recall probe |
|
|
365
368
|
| `add_document` | Saves text as a file under `documents/` and indexes it |
|
|
366
369
|
| `update_document` | Replaces a document's content and re-indexes it |
|
|
367
370
|
| `remove_document` | Removes a document's chunks from the index, and optionally the file |
|
|
@@ -294,6 +294,24 @@ search:
|
|
|
294
294
|
# Example: "work_kb", "research_kb", "personal_kb"
|
|
295
295
|
collection_name: "knowledge_base"
|
|
296
296
|
|
|
297
|
+
# HNSW ef_search — search-time exploration depth of the ChromaDB HNSW
|
|
298
|
+
# index (GH #287). ChromaDB's built-in default is 100; higher values raise
|
|
299
|
+
# the chance that an isolated / recently-inserted chunk is found by its own
|
|
300
|
+
# vector (lower self-recall miss rate), at a roughly linear latency cost.
|
|
301
|
+
# Valid: integer >= 1 (invalid values fall back to 100 with a WARN).
|
|
302
|
+
#
|
|
303
|
+
# HONEST LIMITATION: the value only applies to collections CREATED after
|
|
304
|
+
# the change. ChromaDB's collection.modify() updates the stored metadata
|
|
305
|
+
# but does NOT change search behavior — not even after reopening the
|
|
306
|
+
# client (verified empirically on chromadb 1.5.9). To apply a new value:
|
|
307
|
+
# set it here, then run reindex_documents(full_rebuild=True) — the nuclear
|
|
308
|
+
# rebuild with staging swap creates a fresh collection with the new
|
|
309
|
+
# ef_search. A plain reindex_documents(force=True) re-embeds in place and
|
|
310
|
+
# is NOT enough. The self_recall field of get_index_stats() measures the
|
|
311
|
+
# effect (hnsw_ef_search reports the value actually in use). Default: 100
|
|
312
|
+
# (preserves prior behavior).
|
|
313
|
+
ef_search: 100
|
|
314
|
+
|
|
297
315
|
# -----------------------------------------------------------------------
|
|
298
316
|
# FTS5 Lexical Fast-Path (v4.8.2+, opt-in — default OFF pending v4.9.0)
|
|
299
317
|
# -----------------------------------------------------------------------
|
|
@@ -569,6 +569,9 @@ _TEXT_SCALAR_TYPES = (str, int, float, bool, datetime.date)
|
|
|
569
569
|
# CONFIG DATACLASS
|
|
570
570
|
# ============================================================================
|
|
571
571
|
|
|
572
|
+
# GH #287: ChromaDB HNSW default ef_search — the fallback for search.ef_search.
|
|
573
|
+
DEFAULT_EF_SEARCH = 100
|
|
574
|
+
|
|
572
575
|
|
|
573
576
|
def _resolve_path(raw, default: Path) -> Path:
|
|
574
577
|
"""Resolve a path from YAML (string) or use default (Path).
|
|
@@ -847,6 +850,16 @@ class Config:
|
|
|
847
850
|
)
|
|
848
851
|
)
|
|
849
852
|
|
|
853
|
+
# GH #287: last field on purpose — the api-surface gate treats dataclass
|
|
854
|
+
# fields as positional constructor args, so new fields go at the end.
|
|
855
|
+
# HNSW ef_search: search-time exploration depth for the ChromaDB HNSW
|
|
856
|
+
# index. Default 100 = ChromaDB's built-in default. Higher values raise
|
|
857
|
+
# self-recall of isolated vectors at a linear latency cost, but the value
|
|
858
|
+
# only takes effect on collections CREATED after the change — ChromaDB
|
|
859
|
+
# ignores configuration updates on existing indexes (verified empirically,
|
|
860
|
+
# see docs/reindex-operations.md), so apply it and reindex.
|
|
861
|
+
ef_search: int = field(default_factory=lambda: _get("search", "ef_search", DEFAULT_EF_SEARCH))
|
|
862
|
+
|
|
850
863
|
def __post_init__(self):
|
|
851
864
|
"""Validate config values and ensure directories exist."""
|
|
852
865
|
self._validate_chunking()
|
|
@@ -862,7 +875,7 @@ class Config:
|
|
|
862
875
|
self._ensure_directories()
|
|
863
876
|
|
|
864
877
|
def _validate_chunking(self) -> None:
|
|
865
|
-
"""Bound-check chunk_size / chunk_overlap / default_results / max_results."""
|
|
878
|
+
"""Bound-check chunk_size / chunk_overlap / default_results / max_results / ef_search."""
|
|
866
879
|
if not isinstance(self.chunk_size, int) or self.chunk_size < 100:
|
|
867
880
|
print(f"[WARN] chunk_size={self.chunk_size} invalid, using 1000", file=sys.stderr)
|
|
868
881
|
self.chunk_size = 1000
|
|
@@ -880,6 +893,11 @@ class Config:
|
|
|
880
893
|
self.default_results = 5
|
|
881
894
|
if not isinstance(self.max_results, int) or self.max_results < 1:
|
|
882
895
|
self.max_results = 100
|
|
896
|
+
# GH #287: ef_search must be a positive integer; ChromaDB itself accepts
|
|
897
|
+
# 0 without complaint, so the guard lives here (type() rejects bool).
|
|
898
|
+
if type(self.ef_search) is not int or self.ef_search < 1:
|
|
899
|
+
print(f"[WARN] ef_search={self.ef_search!r} invalid, using {DEFAULT_EF_SEARCH}", file=sys.stderr)
|
|
900
|
+
self.ef_search = DEFAULT_EF_SEARCH
|
|
883
901
|
|
|
884
902
|
def _validate_indexing(self) -> None:
|
|
885
903
|
"""v4.8.0 Fase 3 — clamp batch_size [1,5000] and parallel_workers [1,16].
|
|
@@ -294,6 +294,24 @@ search:
|
|
|
294
294
|
# Example: "work_kb", "research_kb", "personal_kb"
|
|
295
295
|
collection_name: "knowledge_base"
|
|
296
296
|
|
|
297
|
+
# HNSW ef_search — search-time exploration depth of the ChromaDB HNSW
|
|
298
|
+
# index (GH #287). ChromaDB's built-in default is 100; higher values raise
|
|
299
|
+
# the chance that an isolated / recently-inserted chunk is found by its own
|
|
300
|
+
# vector (lower self-recall miss rate), at a roughly linear latency cost.
|
|
301
|
+
# Valid: integer >= 1 (invalid values fall back to 100 with a WARN).
|
|
302
|
+
#
|
|
303
|
+
# HONEST LIMITATION: the value only applies to collections CREATED after
|
|
304
|
+
# the change. ChromaDB's collection.modify() updates the stored metadata
|
|
305
|
+
# but does NOT change search behavior — not even after reopening the
|
|
306
|
+
# client (verified empirically on chromadb 1.5.9). To apply a new value:
|
|
307
|
+
# set it here, then run reindex_documents(full_rebuild=True) — the nuclear
|
|
308
|
+
# rebuild with staging swap creates a fresh collection with the new
|
|
309
|
+
# ef_search. A plain reindex_documents(force=True) re-embeds in place and
|
|
310
|
+
# is NOT enough. The self_recall field of get_index_stats() measures the
|
|
311
|
+
# effect (hnsw_ef_search reports the value actually in use). Default: 100
|
|
312
|
+
# (preserves prior behavior).
|
|
313
|
+
ef_search: 100
|
|
314
|
+
|
|
297
315
|
# -----------------------------------------------------------------------
|
|
298
316
|
# FTS5 Lexical Fast-Path (v4.8.2+, opt-in — default OFF pending v4.9.0)
|
|
299
317
|
# -----------------------------------------------------------------------
|
|
@@ -382,6 +382,98 @@ class DocumentParser:
|
|
|
382
382
|
|
|
383
383
|
return False
|
|
384
384
|
|
|
385
|
+
@staticmethod
|
|
386
|
+
def _excludes_directory(path: Path, base_dir: Path, patterns: List[str]) -> bool:
|
|
387
|
+
"""Check if a directory and everything below it is excluded.
|
|
388
|
+
|
|
389
|
+
A "folder/*" pattern never matches the folder's own relative path, so
|
|
390
|
+
the walk used to enter the folder and drop its files one by one
|
|
391
|
+
(GH #296). The pattern is tested here without its trailing "/*":
|
|
392
|
+
a directory matching that stem has its whole content excluded.
|
|
393
|
+
Directories only — applied to a file, "_*/*" would also exclude a
|
|
394
|
+
root file named "_index.md".
|
|
395
|
+
"""
|
|
396
|
+
if DocumentParser._should_exclude(path, base_dir, patterns):
|
|
397
|
+
return True
|
|
398
|
+
|
|
399
|
+
try:
|
|
400
|
+
rel = path.relative_to(base_dir)
|
|
401
|
+
except ValueError:
|
|
402
|
+
rel = path
|
|
403
|
+
|
|
404
|
+
rel_str = str(rel).replace("\\", "/")
|
|
405
|
+
|
|
406
|
+
for pattern in patterns:
|
|
407
|
+
stem = pattern.rstrip("*")
|
|
408
|
+
if stem != pattern and stem.endswith("/") and fnmatch.fnmatch(rel_str, stem[:-1]):
|
|
409
|
+
return True
|
|
410
|
+
|
|
411
|
+
return False
|
|
412
|
+
|
|
413
|
+
@staticmethod
|
|
414
|
+
def _is_excluded_from_scan(path: Path, base_dir: Path, patterns: List[str]) -> bool:
|
|
415
|
+
"""Check if the scan leaves a file out: it is excluded, or a folder above it is.
|
|
416
|
+
|
|
417
|
+
The walk never enters an excluded folder, so a file below one is left
|
|
418
|
+
out even when no pattern matches the file's own path — a pattern that
|
|
419
|
+
names the folder, like "Archive/old", matches no file path.
|
|
420
|
+
"""
|
|
421
|
+
if DocumentParser._should_exclude(path, base_dir, patterns):
|
|
422
|
+
return True
|
|
423
|
+
|
|
424
|
+
try:
|
|
425
|
+
rel = path.relative_to(base_dir)
|
|
426
|
+
except ValueError:
|
|
427
|
+
return False
|
|
428
|
+
|
|
429
|
+
return any(
|
|
430
|
+
DocumentParser._excludes_directory(base_dir.joinpath(*rel.parts[:depth]), base_dir, patterns)
|
|
431
|
+
for depth in range(1, len(rel.parts))
|
|
432
|
+
)
|
|
433
|
+
|
|
434
|
+
@staticmethod
|
|
435
|
+
def _yields_file(filepath: Path, directory: Path, supported: set, exclude: List[str]) -> bool:
|
|
436
|
+
"""The filter the scan applies to each file of a folder it walks."""
|
|
437
|
+
fname = filepath.name
|
|
438
|
+
if fname.startswith((".rag-pending-", "~$")): # staging file or Office owner file
|
|
439
|
+
return False
|
|
440
|
+
# supported_formats holds suffixes (".go") and exact filenames ("Dockerfile")
|
|
441
|
+
if filepath.suffix.lower() not in supported and fname not in supported:
|
|
442
|
+
return False
|
|
443
|
+
if exclude and DocumentParser._should_exclude(filepath, directory, exclude):
|
|
444
|
+
return False
|
|
445
|
+
return is_path_within(directory, filepath)
|
|
446
|
+
|
|
447
|
+
@staticmethod
|
|
448
|
+
def _as_scanned(path: Path) -> Optional[Path]:
|
|
449
|
+
"""Return a path as iter_files() yields it, or None when it is not below documents_dir.
|
|
450
|
+
|
|
451
|
+
The scan walks the resolved documents folder, so its paths start
|
|
452
|
+
there. An observer reports paths below the folder as it is configured,
|
|
453
|
+
which differs when the configured folder is a link.
|
|
454
|
+
"""
|
|
455
|
+
configured = Path(config.documents_dir).expanduser()
|
|
456
|
+
directory = resolve_path(configured)
|
|
457
|
+
for root in (configured, directory):
|
|
458
|
+
try:
|
|
459
|
+
return directory / Path(path).relative_to(root)
|
|
460
|
+
except ValueError:
|
|
461
|
+
continue
|
|
462
|
+
return None
|
|
463
|
+
|
|
464
|
+
@staticmethod
|
|
465
|
+
def _scan_yields(filepath: Path) -> bool:
|
|
466
|
+
"""Check if a full scan would yield this file, given the path as the scan sees it."""
|
|
467
|
+
directory = resolve_path(Path(config.documents_dir).expanduser())
|
|
468
|
+
exclude = config.exclude_patterns
|
|
469
|
+
if not DocumentParser._yields_file(filepath, directory, set(config.supported_formats), exclude):
|
|
470
|
+
return False
|
|
471
|
+
rel = filepath.relative_to(directory)
|
|
472
|
+
return not any(
|
|
473
|
+
DocumentParser._excludes_directory(directory.joinpath(*rel.parts[:depth]), directory, exclude)
|
|
474
|
+
for depth in range(1, len(rel.parts))
|
|
475
|
+
)
|
|
476
|
+
|
|
385
477
|
def iter_files(self, directory: Path = None):
|
|
386
478
|
"""Yield supported paths without loading content; follow contained links only."""
|
|
387
479
|
directory = resolve_path((Path(directory) if directory else config.documents_dir).expanduser())
|
|
@@ -402,19 +494,12 @@ class DocumentParser:
|
|
|
402
494
|
d
|
|
403
495
|
for d in dirs
|
|
404
496
|
if is_path_within(directory, Path(root) / d)
|
|
405
|
-
and not self.
|
|
497
|
+
and not self._excludes_directory(Path(root) / d, directory, exclude)
|
|
406
498
|
]
|
|
407
499
|
|
|
408
500
|
for fname in files:
|
|
409
|
-
if fname.startswith((".rag-pending-", "~$")): # staging file or Office owner file
|
|
410
|
-
continue
|
|
411
501
|
filepath = Path(root) / fname
|
|
412
|
-
|
|
413
|
-
if filepath.suffix.lower() not in supported and fname not in supported:
|
|
414
|
-
continue
|
|
415
|
-
if exclude and self._should_exclude(filepath, directory, exclude):
|
|
416
|
-
continue
|
|
417
|
-
if not is_path_within(directory, filepath):
|
|
502
|
+
if not self._yields_file(filepath, directory, supported, exclude):
|
|
418
503
|
continue
|
|
419
504
|
resolved = str(resolve_path(filepath))
|
|
420
505
|
if resolved not in seen_files:
|