# Search with files

Use `records.search` or `ledgers.search` with text, files, or both. The selected
local store or hosted connection determines the corpus. Query files are temporary
inputs: supplying one does not upload a persistent File or create a Record.

```python
from pathlib import Path

client.records.search(files=[Path("brief.pdf")], limit=10)
client.records.search(query={"text": "evidence for corrosion prevention"},
                      files=[Path("brief.pdf")], limit=10)
client.records.search(query={"files": [{"ledger_id": ledger_id, "file_id": file_id}]})
```

```sh
op-sys records search --file brief.pdf --limit 10
op-sys records search --file brief.pdf --query '{"text":"corrosion prevention"}'
```

The SDK `files` argument and repeatable CLI `--file` option read explicitly supplied
local paths. Paths never become server filesystem access. MCP tools
`op_sys_records_search` and `op_sys_ledgers_search` accept the same `query` object
as JSON HTTP requests: `files` contains existing `{ledger_id, file_id}` references
or `{name, media_type, bytes_base64}` byte inputs. Text is optional. Scope, exact
filters, limits, cursor continuation and permissions work as for text search.

HTTP also accepts multipart at POST `/v1/records/search` and `/v1/ledgers/search`:
an optional `request` field contains JSON search arguments; repeated `files` fields
contain file parts. Use the ordinary endpoint credentials and tenant selection.

```sh
curl "$VEYLAR_API/v1/records/search" \
  -H "Authorization: Bearer $VEYLAR_TOKEN" \
  -H "X-Veylar-Tenant: $VEYLAR_TENANT" \
  -F 'request={"query":{"text":"corrosion prevention"},"limit":10}' \
  -F 'files=@brief.pdf;type=application/pdf'
```

## Formats and evidence

| Format | Extracted evidence and locations | Limits of interpretation |
| --- | --- | --- |
| UTF-8 TXT, Markdown, textual code | Text with line numbers | No code execution or Markdown rendering. |
| CSV / TSV | Header-labelled rows, original row numbers | Strict delimited text; inconsistent row widths are rejected. |
| JSON / JSONL | Scalar values with field paths; JSONL line identity | JSON values, not application-specific meaning. |
| YAML / XML | Scalar values and structural paths | Safe YAML only; aliases/custom tags and XML DTD/entities are rejected. |
| HTML / EPUB | Text blocks, sections and EPUB spine order | No linked-resource fetching; scripts/styles are omitted. |
| PDF | Extractable text with page numbers | No OCR; reading order and tables depend on embedded text layout. Encrypted PDFs are unsupported. |
| DOCX | Paragraphs, table row/cell positions, headers/footers/notes | No pagination guarantee, tracked-change interpretation or embedded-object processing. |
| PPTX | Slide text and related notes, slide identity | No chart interpretation or rendering; text follows document element order. |
| XLSX | Sheet names and cell addresses | Formula cells are omitted, including potentially stale cached values. No recalculation, macros or chart interpretation. |

The same extractor serves query files and accepted record attachments. A result's
`matches` identifies `file_id` when evidence comes from an attachment, plus the
available location and original text excerpt. Payload evidence uses `location.path`.
Attachment search requires both record access and `files.read` on its ledger;
without file access, attachment passages do not participate in ranking or excerpts.
Ledger search searches definitions/metadata, not hidden record/attachment contents.

Embedded images, charts, audio/video and scanned pages are not understood. Detectable
missing modalities and omitted formulas produce `coverage: partial` with
`unsupported_content`; this is text extraction, not a completeness claim about a
document's visual meaning. Unsupported or unprocessable attachments leave explicit
partial source coverage. File-only queries with no extractable text return
`unsupported`; malformed inputs return `invalid_input`. File references additionally
require currently available bytes and independent file access.

## Processing and retention

- Up to eight query files, 8 MiB combined bytes; multipart bodies up to 9 MiB and
  JSON/MCP search messages up to 12 MiB including base64 overhead.
- Per file: 512 KiB extracted UTF-8 text, 4,096 structural blocks, 256 PDF pages;
  container expansion up to 32 MiB / 4,096 entries. Suspicious archive paths,
  duplicate names, symlinks and excessive compression are rejected.
- Query files produce up to 32 distinct 384-token passages in total, with overlap.
  Every passage contributes to retrieval. Text-plus-file queries give the text
  higher weight; passage vectors are not averaged into one document vector.
  Oversized queries fail explicitly rather than silently truncating documents.
- Parsers have a ten-second wall deadline; complete file-query preparation has a
  thirty-second budget. Retrieval retains its separate five-second budget. These
  are failure ceilings, not expected ordinary response times or performance SLAs.
- Attachment indexing admits up to 8 MiB of file inputs per record and 1,024 total
  projected passages. A file exceeding processing limits is excluded as a unit
  and source coverage is partial; accepted records are not changed.

Temporary bytes pass through bounded memory and private process pipes; no temporary
document is written to disk or ordinary logs. Saved cursors retain encrypted query
representations and source bindings, not uploaded query bytes. File access and
identity are rechecked on continuation. Deleted/unavailable or newly restricted
references cannot be recovered through an old cursor. Expired contexts are swept
by requests and the index worker; inactive local stores sweep on next activity.

CLI interruption stops the active parser. Hosted disconnects cancel preparation;
POSIX process-group cleanup terminates inference and parser children together.
Process cleanup depends on the host platform. The public interface returns
results directly rather than creating an asynchronous job resource.

Text and file relevance search requires a configured search runtime.
Ask the service operator to configure its parser and inference dependencies.
Exact filtering does not require an inference model.
