Search a Knowledge Base Like a Folder
Search a knowledge base line by line — file-name patterns, context, exact counts, paging, and how to read a search that finds nothing.
UnieAI KB Super treats every parsed document as one text file and compares it line by line. Knowledge base search therefore behaves like searching a folder: you name the text or pattern to match, you can narrow the search to file names, and what comes back is the file, the line number and that line, not a condensed summary.
Results are always limited by the caller's access, the bound knowledge bases, the document you name and the as_of_date version snapshot. Files outside that scope are never compared.
Two tools
| Tool | Use it for | Main parameters | Returns |
|---|---|---|---|
kb_search | Ordinary questions, and letting an agent choose the query | query, limit, document_id, as_of_date | Matching passages with their source |
kb_grep | Line numbers, file-name scope, exact counts, paging | pattern, glob, regex, context_lines, count_only, max, offset | Matching lines, or per-file counts |
These entry points search the same parsed text with different matching behavior:
| Entry point | Matching | When nothing matches |
|---|---|---|
| Knowledge base Search page | Treats the input as a regular expression | Reports a miss without changing the query |
kb_search and POST /v1/kb/search | Try the complete query as literal text first | May search terms or Chinese fragments instead, reporting pattern_fallback |
kb_grep | Literal text by default; a regular expression only with regex: true | Keeps the original query and reports the miss |
Characters such as ., * and ( have regular-expression meaning on the Search page. Escape them to find the original text, or ask the agent to use the literal mode of kb_grep.
Parameters
| Parameter | Default | Meaning |
|---|---|---|
pattern | required | The text to find; a regular expression when regex is true |
regex | false | The pattern is literal text by default, so ., * and ( are not read as syntax |
ignore_case | true | Set false for a case-sensitive search |
word | false | Match whole words only |
glob | none | Only files whose name matches this pattern, for example *.csv or 2024-* |
context_lines | 0 | Extra lines before and after each match, 0–20 |
max | 20 | Total matching lines requested for this call, shared across the selected KBs; 20 is the default, with no fixed upper ceiling |
offset | 0 | Matching lines to skip within each selected KB; use that KB's next_offset in pages[] |
count_only | false | Return per-file matching-line counts instead of the lines |
document_id | none | Search one document only |
as_of_date | none | Search the document versions in force on that ISO date |
Searching like a folder
Pick a string that must appear in the file: a product name, clause number, error code or date format.
On a large knowledge base, add glob first — *.csv or 2024-* — to keep the search to the files that matter.
Use count_only to count matching lines. It does not count repeated occurrences within a line. Turn it off to read the contents.
Page with max and offset when there are many hits, and add context_lines to read around a match before relying on it.
Turn on regex only when you need pattern matching: invoice|receipt for alternative spellings, INV-\d{6} for a fixed identifier shape, or lookaround such as (?<=order )\d+.
A malformed regular expression fails with the invalid_pattern error code and the reason from both engines; it never degrades into a partial match. A scope too large to finish in time reports a timeout — narrow it with glob or document_id and retry.
Reading the result
When kb_grep finds matches, it returns:
evidence[]: each entry contains anidfor reading the original withkb_fetch,file,line,textandsource. Requested context appears incontext_before/context_after. A shortened long line hasline_truncated; read the original before citing it.pages[]: each KB has its ownkb_id,returned,has_moreandnext_offset. Continue with that entry'skb_idandnext_offset, keeping the same query and scope. Do not apply one KB's offset to every KB.warnings: included when something needs attention. A miss returns the query, explanation and warnings; do not rely on amatches[]or a top-levelcountfield that is not returned.
With count_only, the top-level matching_lines is the total across the scope. Each entry in counts[] contains the KB's matching_lines, documents_matched and per-file counts in files[]. files_truncated means some file details were omitted, not that the total only counts the listed files.
For example, search this text for invoice:
invoice invoice
invoice
receiptmatching_lines is 2, not the 3 occurrences of the word. Matching lines are also not distinct values, business-record counts or the total rows in a table. Use kb_table to read or calculate over the complete worksheet for table sums, rankings and record counts.
A large tool result may be returned as a reference to the complete result. Follow that reference or continue paging; a preview or a single page is not the complete dataset.
When nothing matches
No results does not prove the document lacks the information. These warnings can appear across the different entry points. pattern_fallback belongs to kb_search / REST API, not automatic query changes in exact kb_grep or the Search page:
| Warning | Meaning | What to do next |
|---|---|---|
no_match | No line in scope matched | Try a shorter or more distinctive term, or widen glob |
glob_matched_no_files | Your glob selected no file at all, so nothing was searched | Check the pattern, or search again without glob |
pattern_fallback | The full phrase does not appear verbatim and fragments were used instead; pattern shows what was matched | Treat the fragment as a lead and confirm it with kb_grep |
documents_empty | A document in scope has no searchable text after parsing | Check whether it needs parsing again or OCR |
documents_unavailable | Some documents could not be read right now | Retry later, or narrow the search to other documents |
empty_scope | No parsed document is in scope | Confirm the knowledge base finished parsing |
Before concluding that a document lacks something, search for a distinctive term you know it contains: that separates a wrong scope from genuinely absent content.
Only fallback search in kb_search / REST API may replace an unmatched complete query with terms or Chinese fragments. Chinese fragments have at least three characters to avoid false hits from two-character fragments. Such hits report pattern_fallback; check the surrounding text. Neither kb_grep nor the Search page automatically enables this fallback.
Calculate over a complete worksheet
Excel/CSV counts, sums, averages and rankings require the complete worksheet. Connect the parsed KB in Agent settings, select UnieAI Harness or UnieAI Harness Lite with tool support, and ask in Playground. For example:
Inspect the worksheets and columns in this sales document, then sum sales by product category and sort the totals.
Identify the document, worksheet, columns and filters, and verify that the calculation covers the complete data.
Describe actual missing categories, values or subtotal rows without inventing values or changing the requested scope.Check this sequence in the tool timeline. The agent calls the tools; users do not need to issue their arguments manually.
- Find the correct document with
kb_search/kb_grepand retain the evidence'sdocument_id. A filename or guessed URL is not a document ID. - Use
kb_tablewithlistto inspect worksheets. For multiple sheets, select the exact name and inspect its columns and original header row. - Use
kb_tablewithopento save all rows of the selected worksheet and obtain asaved_resultreference. It uses the active document version, including an active de-identified version. - Use
tool_resultwithdescribe/readto inspect provenance and relevant fields, thenaggregateto calculate over the complete saved rows. For rankings, request sorting or check extrema from that same calculation; an unordered first page is not a ranking. - Verify the answer's document, worksheet, original source-row positions, filters and actual scope. Search-hit counts and preview length are not source-row totals.
Inspect actual values when headers are ambiguous. Do not automatically turn missing values into zero or assign a missing category from the preceding row. Apply merge semantics only when the source workbook explicitly defines merged cells. If a sheet contains both details and subtotal rows, establish the intended scope before summing them together.
Use scanned_rows / matched_rows to check scan and filter coverage. numeric_complete: false indicates missing or invalid numeric data. If group_by_coverage reports unassigned records, disclose the observed count and affected scope without inventing their group. A positive omitted_boundary_ties means remaining tied groups must be read before claiming a unique winner.
Continue reading large tool results
For a large tool result, the platform can save the complete result and pass its reference to the model, then read it as needed and compact conversation history. This does not send every record to the model at once or use randomly selected rows to represent the whole dataset.
| Timeline information | Interpretation |
|---|---|
saved_result | Result ID for tool_result, not a public download URL |
complete_result_saved | This tool result was saved completely; a search result can still contain only matching evidence |
source_complete / provenance | Check source coverage, document, worksheet and active version |
has_more, next_offset, next_character_offset | Continue with the same result ID and returned position when more content remains |
tool_result supports describe for structure and provenance, read for paging, search for finding text within the saved result, and aggregate for structured calculations. Use source_row for an explicitly requested original worksheet row; do not guess its position from a page offset or record identifier. Unread fields, including notes, may still contain the requested information.
Saving a search response or SQL result completely does not make it the entire source table. Open the source with kb_table for Excel/CSV totals; calculate the intended full scope explicitly in an authorized SQL query for database totals. References remain subject to identity, agent and resource permissions.