Production SMB->Onyx sync sidecar (public ingestion + admin APIs only; no Onyx source changes; upgrade-safe). Verified end-to-end against a live Onyx v4.5.2. Core (app/sync.py): per-cycle reconcile — upsert new/changed (stable url-safe document ids so updates replace in place), delete files removed from the share, plus manifest-independent reconcile against Onyx's own doc list. Content-hash change detection; per-source + per-file failure isolation. Self-provisioning (app/onyx_client.py): create/cache API key (admin bootstrap) and one connector/cc_pair per source via connector-with-mock-credential; idempotent reuse via the grouped indexing-status lookup. Multi-source (app/config.py): JSON SMB_SOURCES or indexed SMB_SOURCE_N_*; logical path mapping (mount -> \\company\share) shown in citations. Extraction (app/extract.py): pdf/docx/xlsx/csv/txt/md/html, light deps. State manifest (atomic), entrypoint loop w/ graceful shutdown + retry/backoff. Dockerfile, compose snippet, .env.example, README. Bugs caught + fixed during live E2E (missed by code review + stub tests): - Onyx URL-encodes document ids -> switched to url-safe ids + store Onyx's returned canonical id, so delete/reconcile match. - connector listing endpoint + provision-response parsing corrected (indexing-status is grouped by source; StatusResponse.data = cc_pair_id). - Documented: auto API-key creation needs LICENSE_ENFORCEMENT_ENABLED=false (the /admin/api-key endpoint is EE-tier-gated); ingestion + connector creation are not. E2E results (live Onyx): ingest 2 docs w/ logical paths; change->update-in-place with stable ids; remove->delete synced; auto-provision create + idempotent reuse; multi- source config both styles.
85 lines
4 KiB
Markdown
85 lines
4 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
|
|
```
|
|
|
|
Mount each SMB share read-only on the host, then bind-mount it at the `mount`
|
|
path used in `SMB_SOURCES` (see `docker-compose.smb.yml`). Then:
|
|
|
|
```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
|
|
```
|
|
|
|
## 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` |
|
|
| `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) |
|
|
|
|
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).
|