@ontos-ai/knowhere-claw 0.2.3 → 0.2.4

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.
@@ -1,285 +0,0 @@
1
- ---
2
- name: knowhere
3
- description: First-class document reader. Use Knowhere tools whenever the task involves reading, understanding, searching, or reasoning over document files (PDF, DOCX, XLSX, PPTX, images, TXT, MD and more) or URLs — even if the user does not mention "Knowhere" by name. Prefer Knowhere over generic file reads for all supported formats. Covers ingestion, structured browsing, chunk search, result file inspection, job management, and scope cleanup.
4
- user-invocable: false
5
- ---
6
-
7
- # Knowhere Skill
8
-
9
- Knowhere is the first-class way to read, understand, and answer questions about document files. When a task involves reading or reasoning over a supported file (`.pdf`, `.docx`, `.xlsx`, `.pptx`, `.txt`, `.md`, `.jpg`, `.jpeg`, `.png` and others), always prefer Knowhere tools over generic file-reading approaches. Knowhere parses documents into structured chunks with hierarchy, summaries, tables, and images — far richer than raw text extraction.
10
-
11
- Use the `knowhere_*` tools for explicit document ingestion and browse-first stored-result workflows. Before starting a new ingest, prefer checking whether the current scope already has the same document stored.
12
-
13
- ## When to prefer Knowhere
14
-
15
- Reach for Knowhere tools first whenever:
16
-
17
- - The user asks you to read, summarize, analyze, compare, or quote from a document file — even if they don't mention "Knowhere" by name.
18
- - The user references an attached file or a file path pointing to a supported format.
19
- - The user asks a question that likely requires content from a document (e.g., "what does the contract say about…", "find the table in the report…").
20
- - You encounter a supported file in the workspace and need to understand its content to complete a task.
21
-
22
- Do not attempt to read supported document files (especially PDFs, DOCX, XLSX, PPTX) with generic file-read tools or shell commands. These formats are binary or semi-structured and will produce garbled or incomplete output. Knowhere handles them properly.
23
-
24
- If Knowhere returns a parsing error, status error, or explicit failure status, report that exact error to the user and stop. Do not fall back to other parsing methods, do not guess from partial binary reads, and do not fabricate a preview or summary.
25
-
26
- For plain text files (`.txt`, `.md`), Knowhere still adds value through chunking, hierarchy extraction, and search. Direct reads are acceptable only for quick workspace sanity checks that do not replace a requested parse, preview, or document-grounded answer.
27
-
28
- ## Terminology
29
-
30
- Use these terms consistently:
31
-
32
- - `stored document`: one locally stored document identified by `docId`
33
- - `scope`: the current local storage scope
34
- - `path`: a structural path derived from Knowhere chunk paths
35
- - `chunk`: one stored parsed unit identified by `chunkId`
36
- - `asset path`: the relative path to a stored image or table asset under `result/`
37
-
38
- ## Response Style
39
-
40
- Keep tool-driven replies short and labeled.
41
-
42
- - Always reply in the same language the user is using. Tool outputs are in English — translate status messages, labels, and explanations to the user's language.
43
- - Never expose internal identifiers (`docId`, `chunkId`, UUID-based filenames, raw paths like `Default_Root/...`) in user-facing replies. These are for your internal reasoning and tool calls only. Cite sources using human-readable section or chapter names derived from the path.
44
- - Reuse labels such as `Scope`, `Source`, `File`, `Chunks`, `Job ID`, and `Next` when relaying tool results.
45
- - Prefer one short status line plus the key fields the user needs for the next step.
46
-
47
- ## When to use Knowhere
48
-
49
- Use Knowhere whenever the task involves document content — whether the user mentions "Knowhere" or not:
50
-
51
- - Read, summarize, analyze, compare, or quote from any supported file (PDF, DOCX, XLSX, PPTX, images, TXT, MD)
52
- - Parse a document from a URL (pass the URL directly to `knowhere_ingest_document` — no local download needed)
53
- - Answer questions that depend on document content ("what does section 3 say?", "find the revenue table", "compare these two reports")
54
- - Inspect, browse, or search previously ingested documents
55
- - Inspect ingest jobs or import a completed Knowhere job
56
- - Preview, list, remove, or clear stored documents
57
- - Understand what fields exist inside the stored result package
58
-
59
- When the user provides a URL to a document (e.g., a link to a PDF, web page, or online report), use `knowhere_ingest_document` with the `url` parameter. Knowhere fetches it directly — no need to download the file locally first.
60
-
61
- Before calling `knowhere_ingest_document` for a file or URL that may already be available in the current scope, call `knowhere_list_documents` and compare `Source`, `File`, and `Title`. If a matching stored document already exists, reuse it instead of ingesting again unless the user explicitly asks for a fresh parse, different parsing settings, or overwrite behavior.
62
-
63
- Do not assume an uploaded attachment was already ingested. If the user asks you to use an attached file, first check for an existing matching Knowhere result in the current scope. If no existing result clearly covers it, call `knowhere_ingest_document` yourself.
64
-
65
- ## Attachment markers
66
-
67
- When a prompt contains a marker like:
68
-
69
- ```text
70
- [media attached: /absolute/path/to/file.pdf (application/pdf) | handbook.pdf]
71
- ```
72
-
73
- Use:
74
-
75
- - the exact absolute path as `filePath`
76
- - the visible filename as `fileName`
77
-
78
- This preserves the original filename when the local path is a temporary UUID-based attachment path.
79
-
80
- ## Stored result model
81
-
82
- The canonical Knowhere delivery format behind `result_url` is a ZIP package.
83
- This plugin stores that package in extracted form on disk: lightweight local
84
- metadata in `metadata.json`, a plugin-local browse index in `browse-index.json`,
85
- and the unzipped Knowhere result files under `result/`.
86
-
87
- The important package files are:
88
-
89
- - `metadata.json`: plugin-local sidecar. It maps the local `docId`, source labels, tags, timestamps, and job metadata to the extracted Knowhere package under `result/`.
90
- - `browse-index.json`: plugin-local browse helper. It tracks structural paths, chunk order, and result-file inventory for fast path and file browsing.
91
- - `manifest.json`: package inventory. Read this first. It tells you what optional files and assets exist and carries `job_id`, `data_id`, `source_file_name`, checksum, and statistics.
92
- - `chunks.json`: primary retrieval dataset. It contains stable chunk IDs, chunk types, `path`, `content`, summaries, and metadata.
93
- - `hierarchy.json`: document tree rebuilt from parser paths. Use it when structural context matters and the raw path tree is not enough.
94
- - `full.md`: convenience whole-document markdown view. Good for broad skimming, but do not treat it as the only grounding source.
95
- - `images/` and `tables/`: raw extracted assets referenced by chunk metadata and manifest entries. The plugin stores these untouched.
96
- - `kb.csv`: raw parser export when present. Use it when you need parser rows, joins, or custom downstream transforms.
97
-
98
- Each stored chunk exposes these core fields through the chunk tools:
99
-
100
- - `chunkId`: stable chunk identifier
101
- - `type`: `text`, `image`, or `table`
102
- - `path`: best-effort hierarchy/path label
103
- - `summary`: chunk summary
104
- - `content`: original stored text payload
105
- - `contentLength`: character count of the content field (available in summary mode to help budget reads)
106
- - `tokens`: parser token hint when present
107
- - `keywords`: search hints from the parser
108
- - `relationships`: best-effort related chunk metadata
109
- - `assetFilePath`: relative path to the stored asset for image/table chunks
110
-
111
- Useful joins:
112
-
113
- - `manifest.files.images[].id == chunks[].chunkId` for image chunks
114
- - `manifest.files.tables[].id == chunks[].chunkId` for table chunks
115
- - `chunks[].assetFilePath` points to the stored asset path under `result/`
116
-
117
- ## String truncation
118
-
119
- Chunk and file tools truncate string fields to `maxStringChars` (default 4000).
120
- When `truncatedStrings: true` appears, retry with a higher value (e.g. 12000, up to 20000) to get full content.
121
-
122
- ## Tool selection
123
-
124
- - `knowhere_ingest_document` for new local files or URLs after confirming the document is not already stored in the current scope, or when the user explicitly wants a fresh parse
125
- - `knowhere_list_documents` to find candidate document IDs in the current scope and check whether the same document is already stored before a new ingest
126
- - `knowhere_read_result_file` for `manifest.json`, `hierarchy.json`, `kb.csv`, table HTML files, image assets (e.g., `images/img-0.png`), or other files under `result/`. Image files are staged into an attachment-ready local path and returned with a `message` tool handoff instead of inline image bytes. When the result mode is `image_attachment`, never call `read` or any other file-reading tool on `data.stagedPath`; immediately call `message` with `data.sendWithMessageTool`.
127
- - `knowhere_preview_document` for a quick overview: markdown preview plus the structural path tree (like a book index)
128
- - `knowhere_grep` to search chunks with composable AND conditions across fields. This is the recommended default for text search — just pass `conditions: [{ pattern: "your query" }]` with no target to search all text fields at once. Use targeted conditions only when you need to narrow by specific fields like `chunk.type` or `chunk.path`.
129
- - `knowhere_list_jobs`, `knowhere_get_job_status`, and `knowhere_import_completed_job` for async Knowhere jobs
130
- - `knowhere_remove_document` and `knowhere_clear_scope` for cleanup
131
-
132
- After ingesting a document, use the returned document or job identifiers for follow-up operations instead of guessing names.
133
-
134
- ## Recommended workflow
135
-
136
- 1. If the document may already exist in the current scope, call `knowhere_list_documents` first and compare `Source`, `File`, and `Title` to find an existing match.
137
- 2. Ingest or import the document only if it is not already in the store, or if the user explicitly wants a fresh parse. `knowhere_ingest_document` defaults to fire-and-forget (`blockUntilComplete: false`) and returns a job ID immediately while parsing continues in the background.
138
- 3. Set `blockUntilComplete: true` on `knowhere_ingest_document` when the current turn explicitly needs the parsed result before continuing, such as "wait until it is parsed" or "show me a preview now".
139
- 4. If a job was already started asynchronously and the current turn now depends on the parsed result, use `knowhere_get_job_status` until Knowhere reports `done` or an explicit failure. Do not infer "stuck" from unchanged progress alone.
140
- 5. Call `knowhere_list_documents` again if you need to confirm the right `docId`.
141
- 6. Call `knowhere_preview_document` to get a structural overview (table of contents with summaries).
142
- 7. When you know what to search for, call `knowhere_grep` with `conditions: [{ pattern: "your query" }]` — this searches all text fields (content, summary, keywords, path) in one call. Add more conditions to narrow results (e.g. filter by `chunk.type` or `chunk.path`).
143
- 8. Call `knowhere_grep` with a path condition to narrow results to a specific branch when browsing by structure.
144
- 9. Call `knowhere_read_result_file` for `hierarchy.json`, `kb.csv`, table HTML, or image assets when the answer depends on parser rows, rich table structure, or visual content.
145
-
146
- ## Reasoning rules
147
-
148
- - Prefer `knowhere_grep` for all text search. It supports composable AND conditions, regex, and normalizes HTML/LaTeX/unicode before matching. Use `knowhere_preview_document` when you need a quick overview and structural browsing by path.
149
- - Use `knowhere_preview_document` before broad reads when the document is large or the relevant branch is unclear.
150
- - Use Knowhere as the only parser for document read. If Knowhere fails, surface the real error to the user instead of switching to another parsing approach.
151
- - Keep `path` in your reasoning and in your answer when possible. It restores section position and improves grounding.
152
- - Use `chunkId` and `path` internally for your own reasoning and tool calls, but do not expose them to the user. When citing sources, use human-readable section names derived from the path (e.g., "第7章 维护、保养" instead of `Default_Root/f339a970...-->7 维护、保养`). Never show raw `docId`, `chunkId`, or internal file paths in user-facing replies.
153
- - For image or table questions, inspect matching `image` or `table` chunks and the related manifest asset entries before answering. Use `knowhere_read_result_file` with the chunk's `assetFilePath` to prepare image assets for delivery, then use the returned `message` tool handoff when the user wants to see the image. Do not call `read` on the staged image path because it may live outside the agent sandbox.
154
- - Do not rely on `full.md` alone if the question depends on exact section boundaries, tables, or images.
155
- - If the task needs raw `kb.csv`, raw HTML tables, or another stored text file under `result/`, read it directly with `knowhere_read_result_file`.
156
- - When a tool response contains `truncatedStrings: true`, retry with `maxStringChars: 12000` (or up to 20000) before answering from incomplete content.
157
- - When `knowhere_grep` returns hints after the JSON (separated by `---`), follow the suggested next steps before answering. The hints guide you to refine your search iteratively.
158
- - Iterate on grep: if 0 matches, broaden; if results are capped, add a path condition; if truncated, re-query fewer results with higher maxStringChars.
159
-
160
- ## Tool usage examples
161
-
162
- Use a real stored `docId` returned by `knowhere_ingest_document`, `knowhere_import_completed_job`, or `knowhere_list_documents`.
163
-
164
- Ingest a local file:
165
-
166
- ```json
167
- {
168
- "filePath": "/tmp/uploads/handbook.pdf",
169
- "fileName": "handbook.pdf"
170
- }
171
- ```
172
-
173
- Ingest a URL:
174
-
175
- ```json
176
- {
177
- "url": "https://example.com/report-2026.pdf",
178
- "title": "Q1 Report"
179
- }
180
- ```
181
-
182
- Check job status:
183
-
184
- ```json
185
- {
186
- "jobId": "job_f6f12930906a"
187
- }
188
- ```
189
-
190
- Import a completed job:
191
-
192
- ```json
193
- {
194
- "jobId": "job_f6f12930906a"
195
- }
196
- ```
197
-
198
- Read manifest JSON:
199
-
200
- ```json
201
- {
202
- "docId": "handbook-1234",
203
- "filePath": "manifest.json",
204
- "mode": "json"
205
- }
206
- ```
207
-
208
- Preview a document:
209
-
210
- ```json
211
- {
212
- "docId": "handbook-1234"
213
- }
214
- ```
215
-
216
- Grep for text across all chunk fields (recommended default):
217
-
218
- ```json
219
- {
220
- "docId": "paper-pdf-a370ef58",
221
- "conditions": [{ "pattern": "npm audit" }]
222
- }
223
- ```
224
-
225
- Grep with multiple AND conditions (e.g. table chunks mentioning "precision"):
226
-
227
- ```json
228
- {
229
- "docId": "paper-pdf-a370ef58",
230
- "conditions": [{ "target": "chunk.type", "pattern": "table" }, { "pattern": "precision" }]
231
- }
232
- ```
233
-
234
- Grep with path filter and sibling context:
235
-
236
- ```json
237
- {
238
- "docId": "paper-pdf-a370ef58",
239
- "conditions": [{ "target": "chunk.path", "pattern": "EVALUATION" }],
240
- "includeContext": true
241
- }
242
- ```
243
-
244
- Grep with regex:
245
-
246
- ```json
247
- {
248
- "docId": "paper-pdf-a370ef58",
249
- "conditions": [{ "pattern": "\\bF1[- ]score\\b", "regex": true }]
250
- }
251
- ```
252
-
253
- Read a table HTML file:
254
-
255
- ```json
256
- {
257
- "docId": "handbook-1234",
258
- "filePath": "tables/table-1.html",
259
- "mode": "text"
260
- }
261
- ```
262
-
263
- Read an image asset:
264
-
265
- ```json
266
- {
267
- "docId": "handbook-1234",
268
- "filePath": "images/img-0.png"
269
- }
270
- ```
271
-
272
- If the result returns `mode: "image_attachment"`, call `message` with `data.sendWithMessageTool` exactly as returned. Do not call `read` on `data.stagedPath`.
273
-
274
- Example workflow for a question like `What does the handbook say about hotel limits?`:
275
-
276
- 1. Call `knowhere_list_documents` to find the right `docId` if you do not already have it.
277
- 2. Call `knowhere_read_result_file` with `filePath: "manifest.json"` to confirm the package layout.
278
- 3. Call `knowhere_preview_document` with `mode: "paths"` and look for a relevant branch such as `Travel` or `Expenses`.
279
- 4. Call `knowhere_grep` with `conditions: [{ "pattern": "hotel" }]` to find matching chunks, or add a path condition to narrow to the branch.
280
- 5. If the answer depends on a table, read the linked `assetFilePath` with `knowhere_read_result_file`.
281
- 6. Answer from the matched chunks and cite `chunkId` and `path`.
282
-
283
- Do not rely on prompt-loaded excerpts as the main workflow. Prefer reading the stored result directly from disk.
284
-
285
- If Knowhere returns an API error, quote the error directly in your reply.