Two client-requested changes: 1. Table of contents per source. On each sync the connector writes one index document listing every file on the share, grouped by folder, so the assistant is aware of the full document set even when a search returns only some files. It re-upserts only when the file set changes, is excluded from the orphan-delete reconcile (shares the source prefix but is not a file), and is removed if SMB_WRITE_INDEX is turned off. 2. Shorter citation labels. semantic_identifier is now the file name, not the full path, so the chat/search citation shows "Angebot.pdf" instead of a long truncated Z:\... path. The full network path stays in `link` and metadata; the UI overlay copies it to the clipboard on click, in both the chat view and the licensed Search view. A DOC_FORMAT_VERSION bump re-upserts already-synced files once so existing docs get the new label without waiting for a content change. Verified with a mock-client simulation: 17 checks covering filename labels, full-path copy, index create/update/delete, reconcile whitelist, add/remove sync, and the one-time format-version re-upsert.
113 lines
5.6 KiB
Markdown
113 lines
5.6 KiB
Markdown
# AIDO SMB → Onyx Connector (Phase 1)
|
|
|
|
Syncs files from one or more **SMB/CIFS shares** into Onyx via the public
|
|
**Ingestion API**, with full production behaviour the POC was missing:
|
|
|
|
- **Update & delete sync** — changed files are re-indexed in place; files removed
|
|
from a share are deleted from Onyx (reconciled every cycle).
|
|
- **Self-provisioning** — creates/reuses the Onyx **API key** and one **connector
|
|
(cc_pair)** per source automatically; idempotent across restarts.
|
|
- **Multi-source via Docker config** — any number of shares, defined purely in env.
|
|
- **Logical path mapping** — each document is labelled with the path users
|
|
recognise (`\\company\share\…`), mapped from the local mount via config.
|
|
|
|
It runs as a **sidecar container** and touches **no Onyx source code** — only the
|
|
public ingestion + admin APIs — so it survives Onyx upgrades.
|
|
|
|
> Phase 2 (separate) hides the broken file-preview for these SMB documents in the
|
|
> Onyx UI and shows the logical path instead, via the white-label overlay.
|
|
|
|
## How it works
|
|
|
|
```
|
|
SMB share ──(read-only mount)──▶ smb_connector ──ingestion API──▶ Onyx
|
|
│
|
|
manifest.json (path → document_id + content hash)
|
|
```
|
|
|
|
Each cycle, per source:
|
|
1. Walk the share, hash each eligible file.
|
|
2. **new / changed** (hash differs) → `POST /onyx-api/ingestion` (upsert by stable id).
|
|
3. **gone** (in manifest, not on disk) → `DELETE /onyx-api/ingestion/{id}`.
|
|
4. Reconcile against Onyx's own doc list so deletes still happen if the manifest
|
|
is lost.
|
|
|
|
Document ids are stable (`smb::<source>::<hash of relative path>`), so re-indexing
|
|
a changed file **updates** it rather than duplicating.
|
|
|
|
## Setup
|
|
|
|
```bash
|
|
cd smb-connector
|
|
cp .env.example .env
|
|
# set ONYX_API_KEY (or ONYX_ADMIN_EMAIL/PASSWORD to auto-create one)
|
|
# define your shares in SMB_SOURCES (JSON) or SMB_SOURCE_1_* vars
|
|
```
|
|
|
|
Then bring it up (same `onyx-network`):
|
|
|
|
```bash
|
|
docker compose -f docker-compose.yml -f smb-connector/docker-compose.smb.yml up -d --build smb_connector
|
|
docker compose logs -f smb_connector
|
|
```
|
|
|
|
### SMB mount — two modes
|
|
|
|
**A. In-container mount (recommended, no host mount).** The connector mounts each
|
|
CIFS share itself; you just give it the share + credentials via env:
|
|
|
|
```
|
|
SMB_SOURCE_1_NAME=Finance
|
|
SMB_SOURCE_1_UNC=//nas.company.local/finance # or _SERVER + _SHARE
|
|
SMB_SOURCE_1_MOUNT=/mnt/smb/finance # where to mount it in the container
|
|
SMB_SOURCE_1_LOGICAL=\\company\finance # path shown in Onyx
|
|
SMB_SOURCE_1_USERNAME=svc_onyx
|
|
SMB_SOURCE_1_PASSWORD=… # kept in a 0600 creds file, never in the process list
|
|
SMB_SOURCE_1_DOMAIN=COMPANY # optional
|
|
# SMB_SOURCE_1_VERS=3.0 # SMB dialect, default 3.0
|
|
```
|
|
|
|
This needs two Linux capabilities on the container (already set in
|
|
`docker-compose.smb.yml`): `cap_add: [SYS_ADMIN, DAC_READ_SEARCH]` +
|
|
`security_opt: [apparmor:unconfined]` (or `privileged: true` if your host is
|
|
stricter). The host kernel must have the `cifs` module (standard on Linux). The
|
|
share is mounted **read-only** and unmounted cleanly on container stop.
|
|
|
|
**B. Host mount (legacy).** Mount the share on the host and bind-mount it into the
|
|
container, and **omit** the `_UNC`/`_SERVER` vars for that source so it isn't
|
|
CIFS-mounted a second time — `_MOUNT` then just points at the bind-mounted path.
|
|
|
|
## Configuration
|
|
|
|
| Var | Purpose |
|
|
|-----|---------|
|
|
| `ONYX_API_URL` | Onyx API base (e.g. `http://api_server:8080`) |
|
|
| `ONYX_API_KEY` | API key; if empty, auto-created from admin creds and cached |
|
|
| `ONYX_ADMIN_EMAIL` / `ONYX_ADMIN_PASSWORD` | Bootstrap creds to auto-create the key + connectors |
|
|
| `SMB_SOURCES` | JSON list of `{name, mount, logical, cc_pair_id?}` |
|
|
| `SMB_SOURCE_<N>_NAME/_MOUNT/_LOGICAL/_CC_PAIR_ID` | Indexed alternative to `SMB_SOURCES` |
|
|
| `SMB_SOURCE_<N>_UNC` (or `_SERVER`+`_SHARE`) | In-container CIFS mount: the share to mount at `_MOUNT` |
|
|
| `SMB_SOURCE_<N>_USERNAME/_PASSWORD/_DOMAIN/_VERS` | CIFS credentials + dialect (default `3.0`); omit user for guest |
|
|
| `INGESTION_INTERVAL_SECONDS` | Reconcile interval (default 300) |
|
|
| `INCLUDE_EXTENSIONS` | File types to ingest (default pdf,docx,txt,md,csv,xlsx,html) |
|
|
| `MAX_FILE_MB` | Skip files larger than this (default 50) |
|
|
| `SMB_WRITE_INDEX` | Write a per-source index (table-of-contents) document listing every file, so the assistant is aware of the full set (default on; `0`/`false` to disable) |
|
|
|
|
State (manifest + cached key/cc_pair) lives in the mounted `/app/state` volume.
|
|
|
|
## Notes / scope
|
|
|
|
- **Extraction** is the light set (PDF, DOCX, XLSX, CSV, TXT/MD, HTML). Legacy
|
|
`.doc`/`.xls` and scanned-image PDFs are skipped (no OCR) — Phase-1 scope.
|
|
- **Auth for provisioning**: creating the API key/connectors needs one admin
|
|
credential the first time. At steady state only the cached API key is used.
|
|
- **API-key auto-creation requires `LICENSE_ENFORCEMENT_ENABLED=false`** on the Onyx
|
|
deployment (verified against v4.5.2): the `/admin/api-key` endpoint is EE-tier-gated
|
|
and returns HTTP 402 when enforcement is on (the default). CE/white-label deployments
|
|
run with it off, so this is fine — and if you'd rather not rely on it, just supply a
|
|
pre-made `ONYX_API_KEY`. Connector/cc_pair creation and the ingestion API itself are
|
|
**not** tier-gated and work on plain CE.
|
|
- **Document ids are URL-safe** (`smb_<source>_<hash>`), matching how Onyx stores/returns
|
|
them, so update and delete reconcile reliably (verified end-to-end).
|
|
- **`smb://` links** can't open from a browser; the logical path is stored for
|
|
display (Phase 2 surfaces it in the UI and hides the dead preview).
|