ftree-kg 0.8.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.
ftree_kg-0.8.0/LICENSE ADDED
@@ -0,0 +1,94 @@
1
+ Elastic License 2.0
2
+
3
+ URL: https://www.elastic.co/licensing/elastic-license
4
+
5
+ ## Acceptance
6
+
7
+ By using the software, you agree to all of the terms and conditions below.
8
+
9
+ ## Copyright License
10
+
11
+ The licensor grants you a non-exclusive, royalty-free, worldwide,
12
+ non-sublicensable, non-transferable license to use, copy, distribute, make
13
+ available, and prepare derivative works of the software, in each case subject to
14
+ the limitations and conditions below.
15
+
16
+ ## Limitations
17
+
18
+ **You may not provide the software to third parties as a hosted or managed
19
+ service, where the service provides users with access to any substantial set of
20
+ the features or functionality of the software.**
21
+
22
+ You may not move, change, disable, or circumvent the license key functionality
23
+ in the software, and you may not remove or obscure any functionality in the
24
+ software that is protected by the license key.
25
+
26
+ You may not alter, remove, or obscure any licensing, copyright, or other notices
27
+ of the licensor in the software. Any use of the licensor's trademarks is subject
28
+ to applicable law.
29
+
30
+ ## Patents
31
+
32
+ The licensor grants you a license, under any patent claims the licensor can
33
+ license, or becomes able to license, to make, have made, use, sell, offer for
34
+ sale, import and have imported the software, in each case subject to the
35
+ limitations and conditions in this license. This license does not cover any
36
+ patent claims that you cause to be infringed by modifications or additions to the
37
+ software. If you or your company make any written claim that the software
38
+ infringes or contributes to infringement of any patent, your patent license for
39
+ the software granted under these terms ends immediately. If your company makes
40
+ such a claim, your patent license ends immediately for work on behalf of your
41
+ company.
42
+
43
+ ## Notices
44
+
45
+ You must ensure that anyone who gets a copy of any part of the software from you
46
+ also gets a copy of these terms or the URL for them above, as well as copies of
47
+ any plain-text lines beginning with "Required Notice:" that the licensor provided
48
+ with the software. For example:
49
+
50
+ Required Notice: Copyright (c) 2026 Flux Frontiers
51
+
52
+ ## No Other Rights
53
+
54
+ These terms do not imply any other licenses not expressly granted in this
55
+ license.
56
+
57
+ ## Termination
58
+
59
+ If you use the software in violation of these terms, such use is not licensed,
60
+ and your licenses will automatically terminate. If the licensor provides you with
61
+ a notice of your violation, and you cease all violation of this license no later
62
+ than 30 days after you receive that notice, your licenses will be reinstated
63
+ retroactively. However, if you violate these terms after such reinstatement, any
64
+ additional violation of these terms will cause your licenses to terminate
65
+ automatically and permanently.
66
+
67
+ ## No Liability
68
+
69
+ *As far as the law allows, the software comes as is, without any warranty or
70
+ condition, and the licensor will not be liable to you for any damages arising out
71
+ of these terms or the use or nature of the software, under any kind of legal
72
+ claim.*
73
+
74
+ ## Definitions
75
+
76
+ The **licensor** is the entity offering these terms, and the **software** is the
77
+ software the licensor makes available under these terms, including any portion of
78
+ it.
79
+
80
+ **You** refers to the individual or entity agreeing to these terms.
81
+
82
+ **Your company** is any legal entity, sole proprietorship, or other kind of
83
+ organization that you work for, plus all organizations that have control over,
84
+ are under the control of, or are under common control with that organization.
85
+ Control means ownership of substantially all the assets of an entity, or the
86
+ power to direct its management and policies by vote, contract, or otherwise.
87
+ Control can be direct or indirect.
88
+
89
+ **Your licenses** are all the licenses granted to you for the software under
90
+ these terms.
91
+
92
+ **Use** means anything you do with the software requiring one of your licenses.
93
+
94
+ **Trademark** means trademarks, service marks, and similar rights.
@@ -0,0 +1,331 @@
1
+ Metadata-Version: 2.4
2
+ Name: ftree-kg
3
+ Version: 0.8.0
4
+ Summary: KGModule for file tree knowledge graphs
5
+ License-Expression: Elastic-2.0
6
+ License-File: LICENSE
7
+ Keywords: knowledge-graph,filesystem,lancedb,sqlite,semantic-search,kgmodule
8
+ Author: Eric G. Suchanek, PhD
9
+ Author-email: suchanek@flux-frontiers.com
10
+ Requires-Python: >=3.12,<3.14
11
+ Classifier: Development Status :: 4 - Beta
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
14
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
15
+ Classifier: Programming Language :: Python :: 3
16
+ Classifier: Programming Language :: Python :: 3.12
17
+ Classifier: Programming Language :: Python :: 3.13
18
+ Provides-Extra: all
19
+ Provides-Extra: dev
20
+ Provides-Extra: kgdeps
21
+ Requires-Dist: click (>=8.1.0,<9)
22
+ Requires-Dist: detect-secrets (>=1.5.0) ; extra == "all"
23
+ Requires-Dist: detect-secrets (>=1.5.0) ; extra == "dev"
24
+ Requires-Dist: doc-kg (>=0.11.0) ; extra == "kgdeps"
25
+ Requires-Dist: doc-kg (>=0.12.0) ; extra == "all"
26
+ Requires-Dist: kgmodule-utils (>=0.2.4)
27
+ Requires-Dist: lancedb (>=0.29.0)
28
+ Requires-Dist: mypy (>=1.10.0) ; extra == "all"
29
+ Requires-Dist: mypy (>=1.10.0) ; extra == "dev"
30
+ Requires-Dist: pillow (>=10.0.0)
31
+ Requires-Dist: pre-commit (>=4.5.1) ; extra == "all"
32
+ Requires-Dist: pre-commit (>=4.5.1) ; extra == "dev"
33
+ Requires-Dist: pycode-kg (>=0.16.0) ; extra == "kgdeps"
34
+ Requires-Dist: pycode-kg (>=0.17.0) ; extra == "all"
35
+ Requires-Dist: pylint (>=4.0.5) ; extra == "all"
36
+ Requires-Dist: pylint (>=4.0.5) ; extra == "dev"
37
+ Requires-Dist: pytest (>=8.0.0) ; extra == "all"
38
+ Requires-Dist: pytest (>=8.0.0) ; extra == "dev"
39
+ Requires-Dist: pytest-cov (>=5.0.0) ; extra == "all"
40
+ Requires-Dist: pytest-cov (>=5.0.0) ; extra == "dev"
41
+ Requires-Dist: rich (>=13.0.0)
42
+ Requires-Dist: ruff (>=0.4.0) ; extra == "all"
43
+ Requires-Dist: ruff (>=0.4.0) ; extra == "dev"
44
+ Project-URL: Homepage, https://github.com/Flux-Frontiers/FTreeKG
45
+ Project-URL: Repository, https://github.com/Flux-Frontiers/FTreeKG
46
+ Description-Content-Type: text/markdown
47
+
48
+ [![Python](https://img.shields.io/badge/python-3.12%20%7C%203.13-blue.svg)](https://www.python.org/)
49
+ [![License: Elastic-2.0](https://img.shields.io/badge/License-Elastic%202.0-blue.svg)](https://www.elastic.co/licensing/elastic-license)
50
+ [![Version](https://img.shields.io/badge/version-0.8.0-blue.svg)](https://github.com/Flux-Frontiers/FTreeKG/releases)
51
+ [![CI](https://github.com/Flux-Frontiers/FTreeKG/actions/workflows/ci.yml/badge.svg)](https://github.com/Flux-Frontiers/FTreeKG/actions/workflows/ci.yml)
52
+ [![Poetry](https://img.shields.io/endpoint?url=https://python-poetry.org/badge/v0.json)](https://python-poetry.org/)
53
+ [![DOI](https://zenodo.org/badge/1182124358.svg)](https://zenodo.org/badge/latestdoi/1182124358)
54
+
55
+ **FTreeKG** — A Knowledge Graph for Filesystem Hierarchies
56
+ with Semantic Indexing and Per-Format Metadata Extraction
57
+
58
+ *Author: Eric G. Suchanek, PhD*
59
+ *Flux-Frontiers, Liberty TWP, OH*
60
+
61
+ ---
62
+
63
+ ## Overview
64
+
65
+ FTreeKG turns any directory tree into a knowledge graph you can talk to.
66
+ It walks the filesystem, classifies every entry as a file, directory, or
67
+ symlink, captures the cheap stat the OS already exposes — size, mtime,
68
+ mode, symlink target — and reaches one step further to lift per-format
69
+ metadata (image EXIF today; audio, video, and PDF reserved) into a
70
+ JSON blob that travels with each node. The skeleton is persisted to
71
+ SQLite; a LanceDB vector index sits on top for semantic search.
72
+
73
+ The point is to make a filesystem **askable**. *"Where do we keep
74
+ configuration?" "Which photos came from the iPhone in 2023?" "What
75
+ changed in `src/` since the last release?"* — questions that normally
76
+ require some combination of `find`, `mdfind`, manual inspection, and
77
+ guesswork get a single, ranked answer. The graph is small, fast to
78
+ build, and cheap to rebuild, so it works equally well as a one-shot
79
+ analysis tool, an LLM context source, and a structural complement to
80
+ codebase- and document-level knowledge graphs in the same workflow.
81
+
82
+ FTreeKG is a member of the [KGRAG](https://github.com/Flux-Frontiers/kgrag)
83
+ family of knowledge graphs. It uses the same hybrid SQLite-plus-LanceDB
84
+ architecture as its sister projects [PyCodeKG](https://github.com/Flux-Frontiers/pycode_kg)
85
+ (Python source) and [DocKG](https://github.com/Flux-Frontiers/doc_kg)
86
+ (document corpora), exposes itself to KGRAG's federated query layer with
87
+ the dedicated `KGKind.FILETREE` kind, and is built on the shared
88
+ [KGModule](https://github.com/Flux-Frontiers/kg_utils) primitives so it
89
+ slots cleanly into the same agents and pipelines.
90
+
91
+ The technical reading list:
92
+
93
+ - **[docs/SCHEMA.md](docs/SCHEMA.md)** — node kinds, edge types, node-ID
94
+ format, full SQLite and LanceDB column reference, per-format metadata
95
+ fields.
96
+ - **[docs/CHEATSHEET.md](docs/CHEATSHEET.md)** — query patterns, EXIF
97
+ search recipes, snapshot workflows, common questions answered with
98
+ one-liners.
99
+ - **[docs/CLI.md](docs/CLI.md)** — flag-by-flag reference for every
100
+ `ftreekg` subcommand, plus the `pyproject.toml` configuration surface.
101
+ - **[docs/pipeline.md](docs/pipeline.md)** — the build and query
102
+ pipelines as flowing prose, with diagram hints suitable for
103
+ PaperBanana or any other generator.
104
+ - **[docs/MCP.md](docs/MCP.md)** — how the local `.mcp.json` wires
105
+ PyCodeKG and DocKG into AI agents working on this repo, and what a
106
+ dedicated FTreeKG MCP server would look like.
107
+
108
+ ---
109
+
110
+ ## Quick start
111
+
112
+ After installing the package, point `ftreekg build` at any directory.
113
+ The first run wipes any existing index and produces a fresh
114
+ `.filetreekg/` folder with the SQLite graph and the LanceDB vector
115
+ index inside it. Subsequent commands operate against that store with no
116
+ further setup.
117
+
118
+ ```bash
119
+ ftreekg build --repo /path/to/project # walk + extract + embed
120
+ ftreekg query "configuration files" # natural-language search
121
+ ftreekg query "iPhone photos from 2023" # EXIF-grounded search
122
+ ftreekg status # live dashboard
123
+ ftreekg analyze # full Markdown report
124
+ ```
125
+
126
+ The `query` and `pack` commands are deliberately the primary surface:
127
+ `query` returns a ranked list of nodes, `pack` returns the same nodes
128
+ with their metadata rendered as paste-ready blocks for LLM context.
129
+ `status` is the orientation tool — run it whenever you want to know
130
+ what's in the index right now. `analyze` writes a longer report to
131
+ `analysis/filetreekg_analysis.md` with a summary table, an
132
+ ASCII size-by-top-directory bar chart, a depth-3 directory tree, and
133
+ per-kind/per-relation breakdowns.
134
+
135
+ For the full set of commands and flags see [docs/CLI.md](docs/CLI.md);
136
+ for query recipes see [docs/CHEATSHEET.md](docs/CHEATSHEET.md).
137
+
138
+ ---
139
+
140
+ ## Installation
141
+
142
+ FTreeKG requires Python 3.12 or 3.13. The core install pulls Click,
143
+ Rich, LanceDB, Pillow, and the shared `kgmodule-utils` package:
144
+
145
+ ```bash
146
+ pip install ftree-kg # core runtime
147
+ pip install 'ftree-kg[kgdeps]' # add PyCodeKG + DocKG for federation
148
+ poetry add ftree-kg # Poetry equivalent
149
+ ```
150
+
151
+ The `kgdeps` extra is what you want if you're working in a repo where
152
+ PyCodeKG and DocKG are also indexing alongside FTreeKG — it pins
153
+ compatible versions of both. For a complete development setup
154
+ (linting, tests, pre-commit, all extras), see
155
+ [docs/CLI.md#development-setup](docs/CLI.md).
156
+
157
+ ---
158
+
159
+ ## How it works
160
+
161
+ A build runs three meaningful passes. The first walks the tree with
162
+ `Path.rglob`, applies the include/exclude/dotdir rules, and inserts a
163
+ node row per entry plus a `CONTAINS` edge from each parent. The second
164
+ re-stats every file to fill in `size_bytes`. The third — the per-format
165
+ metadata pass — calls into the dispatcher in `ftree_kg.metadata`, which
166
+ opens images with Pillow and decodes camera, lens, capture timestamp,
167
+ GPS coordinates, and dimensions; the resulting dict is JSON-serialized
168
+ into the `metadata` column. A final embedding step builds a canonical
169
+ two-line text document for each node — `"{kind} {basename} at {path}"`
170
+ plus a keyword line that includes path components, basename token
171
+ splits, the file extension, and projected metadata tokens (camera
172
+ make/model, year, year-month, GPS) — embeds them in batches via
173
+ `kg_utils.embedder`, and writes the vectors to a single LanceDB table.
174
+
175
+ That metadata projection is what makes EXIF-grounded queries work
176
+ without any filename hints. A photo whose path is just
177
+ `photos/IMG_0042.jpg` ends up with an embed line that mentions
178
+ `apple iphone 14 pro 2023 2023-07 gps:37.7749,-122.4194`, so a query
179
+ like *"iPhone photos from 2023"* matches it directly. The schema doc
180
+ walks through the embed-text format end-to-end:
181
+ [docs/SCHEMA.md#embed-text-format](docs/SCHEMA.md#embed-text-format).
182
+
183
+ Querying is intentionally simple: the query string is embedded with the
184
+ same model used at build time, LanceDB returns the top-`k` nodes ranked
185
+ by cosine distance, and that's the answer. There is no graph expansion
186
+ phase — filesystem nodes have only `CONTAINS`, which is structural and
187
+ not semantically informative for hop-style retrieval. When the LanceDB
188
+ table is missing or the embedder fails to load, `query` falls back to a
189
+ substring `LIKE` search across `qualname`, `kind`, `docstring`, and
190
+ `metadata`, so it always returns something useful even on a freshly
191
+ extracted tree with no embeddings.
192
+
193
+ The full pipeline is described in flowing prose, layer by layer, in
194
+ [docs/pipeline.md](docs/pipeline.md), which doubles as the input format
195
+ for diagram generators.
196
+
197
+ ---
198
+
199
+ ## Python API
200
+
201
+ Everything the CLI does is one method call away on `FileTreeKG`:
202
+
203
+ ```python
204
+ from ftree_kg import FileTreeKG
205
+
206
+ kg = FileTreeKG(repo_root="/path/to/project")
207
+ kg.build() # wipe=True, embed=True, metadata=True
208
+
209
+ result = kg.query("configuration files", k=5)
210
+ for node in result.nodes:
211
+ print(f"{node['kind']:12} {node['qualname']} ({node['score']:.3f})")
212
+
213
+ stats = kg.stats()
214
+ print(f"{stats['total_nodes']:,} paths, {stats['total_size_bytes']:,} bytes")
215
+
216
+ print(kg.analyze()) # Markdown report as a string
217
+ kg.close()
218
+ ```
219
+
220
+ `build()` accepts `embed=False` and `metadata=False` to skip the
221
+ expensive passes — useful when you want a fast structural index for
222
+ testing, or when the embedder isn't available in CI.
223
+
224
+ ---
225
+
226
+ ## Configuration
227
+
228
+ Indexing scope is configurable from `pyproject.toml`. The block lives
229
+ under `[tool.filetreekg]` and has two keys, both optional:
230
+
231
+ ```toml
232
+ [tool.filetreekg]
233
+ include = ["src", "docs"] # restrict to these top-level directories
234
+ exclude = ["archives"] # skip in addition to the built-in skip list
235
+ ```
236
+
237
+ `include` is a whitelist — when it's non-empty, only paths under one of
238
+ the listed directories are indexed. `exclude` is additive on top of
239
+ the always-skipped names (`venv`, `env`, `__pycache__`, `build`,
240
+ `dist`, `egg-info`, `node_modules`). All dotdirs (`.git`, `.venv`,
241
+ `.codekg`, …) are skipped automatically unless you explicitly list them
242
+ in `include`.
243
+
244
+ CLI flags `--include-dir` and `--exclude-dir` override the config when
245
+ specified. Full precedence rules and per-command examples live in
246
+ [docs/CLI.md](docs/CLI.md).
247
+
248
+ ---
249
+
250
+ ## Storage
251
+
252
+ A built tree gets a single hidden directory:
253
+
254
+ ```
255
+ .filetreekg/
256
+ graph.sqlite # canonical knowledge graph (nodes + edges + metadata)
257
+ lancedb/ # derived vector index (kg_nodes.lance)
258
+ snapshots/ # temporal metric snapshots, keyed by git tree hash
259
+ manifest.json
260
+ <tree-hash>.json
261
+ ```
262
+
263
+ SQLite is **canonical** — it is the source of truth. LanceDB is
264
+ **derived and disposable**: deleting `.filetreekg/lancedb/` and
265
+ re-running `ftreekg build` reproduces it without re-walking the tree
266
+ (the embed pass reads from SQLite). Snapshots are append-only and
267
+ keyed by the git tree hash of the staged index, so they form a
268
+ deterministic timeline you can `diff` between commits or releases.
269
+ `ftreekg install-hooks` writes a pre-commit hook that captures a
270
+ snapshot on every commit.
271
+
272
+ For column-level details — node IDs, every SQLite column, every
273
+ LanceDB column, every per-format metadata field — see
274
+ [docs/SCHEMA.md](docs/SCHEMA.md).
275
+
276
+ ---
277
+
278
+ ## KGRAG federation
279
+
280
+ `FileTreeKG.kind()` returns `"filetree"` (the dedicated
281
+ `KGKind.FILETREE` enum value), and `FileTreeKGAdapter` exposes the
282
+ module to the [KGRAG](https://github.com/Flux-Frontiers/kgrag)
283
+ federation layer. That means a single federated query can combine
284
+ filesystem context with code and document context from PyCodeKG and
285
+ DocKG indexed against the same repo:
286
+
287
+ ```python
288
+ from kg_rag import KGRAG
289
+
290
+ kgrag = KGRAG()
291
+ result = kgrag.query("how do we ship releases",
292
+ kinds=["code", "doc", "filetree"])
293
+ ```
294
+
295
+ For working with the repo through MCP-compatible AI agents — including
296
+ the `.mcp.json` shipped in this checkout and the federated alternative
297
+ to a dedicated FTreeKG MCP server — see [docs/MCP.md](docs/MCP.md).
298
+
299
+ ---
300
+
301
+ ## Citation
302
+
303
+ If you use FTreeKG in research or a project, please cite it:
304
+
305
+ [![DOI](https://zenodo.org/badge/1182124358.svg)](https://zenodo.org/badge/latestdoi/1182124358)
306
+
307
+ **APA**
308
+
309
+ > Suchanek, E. G. (2026). *FTreeKG: Knowledge Graph for Filesystem Hierarchies* (Version 0.8.0) [Software]. Flux-Frontiers. https://doi.org/10.5281/zenodo.1182124358
310
+
311
+ **BibTeX**
312
+
313
+ ```bibtex
314
+ @software{suchanek_ftree_kg,
315
+ author = {Suchanek, Eric G.},
316
+ title = {{FTreeKG}: Knowledge Graph for Filesystem Hierarchies},
317
+ version = {0.8.0},
318
+ year = {2026},
319
+ publisher = {Flux-Frontiers},
320
+ url = {https://github.com/Flux-Frontiers/FTreeKG},
321
+ doi = {10.5281/zenodo.1182124358},
322
+ }
323
+ ```
324
+
325
+ ---
326
+
327
+ ## License
328
+
329
+ [Elastic License 2.0](LICENSE) — free for non-commercial and internal
330
+ use; commercial redistribution requires a license from Flux-Frontiers.
331
+