Skip to content

Connectors

Connectors API Endpoints.

This module provides the API endpoints for managing connectors and their associated documents. Connectors are used to ingest data from various sources (SQL, files, etc.).

create_connector(connector, service, current_user) async

Create a new connector.

Parameters:

  • connector (ConnectorCreate) –

    The connector creation data.

  • service (Annotated[ConnectorService, Depends(get_connector_service)]) –

    The connector service instance.

  • current_user (Annotated[User, Depends(get_current_admin)]) –

    The currently authenticated admin user.

Returns:

  • ConnectorResponse ( ConnectorResponse ) –

    The created connector.

Source code in app/api/v1/endpoints/connectors.py
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
@router.post("/", response_model=ConnectorResponse)
async def create_connector(
    connector: ConnectorCreate,
    service: Annotated[ConnectorService, Depends(get_connector_service)],
    current_user: Annotated[User, Depends(get_current_admin)],
) -> ConnectorResponse:
    """
    Create a new connector.

    Args:
        connector: The connector creation data.
        service: The connector service instance.
        current_user: The currently authenticated admin user.

    Returns:
        ConnectorResponse: The created connector.
    """
    return await service.create_connector(connector)

create_connector_document(connector_id, document, service, current_user) async

Manually add a document to a connector.

Parameters:

  • connector_id (UUID) –

    The ID of the connector.

  • document (ConnectorDocumentCreate) –

    The document creation data.

  • service (Annotated[DocumentService, Depends(get_document_service)]) –

    The document service instance.

  • current_user (Annotated[User, Depends(get_current_admin)]) –

    The currently authenticated admin user.

Returns:

  • ConnectorDocumentResponse ( ConnectorDocumentResponse ) –

    The created document.

Source code in app/api/v1/endpoints/connectors.py
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
@router.post("/{connector_id}/documents", response_model=ConnectorDocumentResponse)
async def create_connector_document(
    connector_id: UUID,
    document: ConnectorDocumentCreate,
    service: Annotated[DocumentService, Depends(get_document_service)],
    current_user: Annotated[User, Depends(get_current_admin)],
) -> ConnectorDocumentResponse:
    """
    Manually add a document to a connector.

    Args:
        connector_id: The ID of the connector.
        document: The document creation data.
        service: The document service instance.
        current_user: The currently authenticated admin user.

    Returns:
        ConnectorDocumentResponse: The created document.
    """
    return await service.create_document(connector_id, document)

delete_connector(connector_id, service, current_user) async

Delete a connector and its resources.

Parameters:

  • connector_id (UUID) –

    The ID of the connector to delete.

  • service (Annotated[ConnectorService, Depends(get_connector_service)]) –

    The connector service instance.

  • current_user (Annotated[User, Depends(get_current_admin)]) –

    The currently authenticated admin user.

Returns:

  • Dict[str, str]

    Dict[str, str]: A success message.

Source code in app/api/v1/endpoints/connectors.py
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
@router.delete("/{connector_id}")
async def delete_connector(
    connector_id: UUID,
    service: Annotated[ConnectorService, Depends(get_connector_service)],
    current_user: Annotated[User, Depends(get_current_admin)],
) -> Dict[str, str]:
    """
    Delete a connector and its resources.

    Args:
        connector_id: The ID of the connector to delete.
        service: The connector service instance.
        current_user: The currently authenticated admin user.

    Returns:
        Dict[str, str]: A success message.
    """
    await service.delete_connector(connector_id)
    return {"message": "Connector deleted successfully"}

delete_document(connector_id, document_id, service, current_user) async

Delete a specific document.

Parameters:

  • connector_id (UUID) –

    The ID of the connector.

  • document_id (UUID) –

    The ID of the document to delete.

  • service (Annotated[DocumentService, Depends(get_document_service)]) –

    The document service instance.

  • current_user (Annotated[User, Depends(get_current_admin)]) –

    The currently authenticated admin user.

Returns:

  • Dict[str, str]

    Dict[str, str]: A success message.

Source code in app/api/v1/endpoints/connectors.py
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
@router.delete("/{connector_id}/documents/{document_id}")
async def delete_document(
    connector_id: UUID,
    document_id: UUID,
    service: Annotated[DocumentService, Depends(get_document_service)],
    current_user: Annotated[User, Depends(get_current_admin)],
) -> Dict[str, str]:
    """
    Delete a specific document.

    Args:
        connector_id: The ID of the connector.
        document_id: The ID of the document to delete.
        service: The document service instance.
        current_user: The currently authenticated admin user.

    Returns:
        Dict[str, str]: A success message.
    """
    await service.delete_document(document_id)
    return {"message": "Document deleted successfully"}

get_connector_documents(connector_id, service, current_user, page=1, size=20, status=None, search=None) async

Get paginated documents for a connector.

Parameters:

  • connector_id (UUID) –

    The ID of the connector.

  • service (Annotated[DocumentService, Depends(get_document_service)]) –

    The document service instance.

  • current_user (Annotated[User, Depends(get_current_admin)]) –

    The currently authenticated admin user.

  • page (int, default: 1 ) –

    The page number.

  • size (int, default: 20 ) –

    The page size.

  • status (Optional[DocStatus], default: None ) –

    Filter by document status.

  • search (Optional[str], default: None ) –

    Search term for file name or path.

Returns:

  • Dict[str, Any]

    Dict[str, Any]: Paginated document results.

Source code in app/api/v1/endpoints/connectors.py
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
@router.get("/{connector_id}/documents", response_model=Dict[str, Any])
async def get_connector_documents(
    connector_id: UUID,
    service: Annotated[DocumentService, Depends(get_document_service)],
    current_user: Annotated[User, Depends(get_current_admin)],
    page: int = 1,
    size: int = 20,
    status: Optional[DocStatus] = None,
    search: Optional[str] = None,
) -> Dict[str, Any]:
    """
    Get paginated documents for a connector.

    Args:
        connector_id: The ID of the connector.
        service: The document service instance.
        current_user: The currently authenticated admin user.
        page: The page number.
        size: The page size.
        status: Filter by document status.
        search: Search term for file name or path.

    Returns:
        Dict[str, Any]: Paginated document results.
    """
    result = await service.get_connector_documents(connector_id, page, size, status, search)
    # The service already returns ConnectorDocumentResponse objects, but we ensure it here.
    result["items"] = [ConnectorDocumentResponse.model_validate(doc) for doc in result["items"]]
    return result

get_connectors(service, current_user) async

List all connectors.

Parameters:

  • service (Annotated[ConnectorService, Depends(get_connector_service)]) –

    The connector service instance.

  • current_user (Annotated[User, Depends(get_current_admin)]) –

    The currently authenticated admin user.

Returns:

  • List[ConnectorResponse]

    List[ConnectorResponse]: A list of all connectors.

Source code in app/api/v1/endpoints/connectors.py
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
@router.get("/", response_model=List[ConnectorResponse])
async def get_connectors(
    service: Annotated[ConnectorService, Depends(get_connector_service)],
    current_user: Annotated[User, Depends(get_current_admin)],
) -> List[ConnectorResponse]:
    """
    List all connectors.

    Args:
        service: The connector service instance.
        current_user: The currently authenticated admin user.

    Returns:
        List[ConnectorResponse]: A list of all connectors.
    """
    return await service.get_connectors()

scan_connector_files(connector_id, service, current_user) async

Trigger manual file scan for a folder connector.

Parameters:

  • connector_id (UUID) –

    The ID of the connector to scan.

  • service (Annotated[ConnectorService, Depends(get_connector_service)]) –

    The connector service instance.

  • current_user (Annotated[User, Depends(get_current_admin)]) –

    The currently authenticated admin user.

Returns:

  • ConnectorResponse ( ConnectorResponse ) –

    The connector being scanned.

Source code in app/api/v1/endpoints/connectors.py
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
@router.post("/{connector_id}/scan-files/", response_model=ConnectorResponse)
@router.post("/{connector_id}/scan-files", response_model=ConnectorResponse)
async def scan_connector_files(
    connector_id: UUID,
    service: Annotated[ConnectorService, Depends(get_connector_service)],
    current_user: Annotated[User, Depends(get_current_admin)],
) -> ConnectorResponse:
    """
    Trigger manual file scan for a folder connector.

    Args:
        connector_id: The ID of the connector to scan.
        service: The connector service instance.
        current_user: The currently authenticated admin user.

    Returns:
        ConnectorResponse: The connector being scanned.
    """
    return await service.scan_connector(connector_id)

stop_connector(connector_id, service, current_user) async

Request to stop a running connector sync.

Parameters:

  • connector_id (UUID) –

    The ID of the connector to stop.

  • service (Annotated[ConnectorService, Depends(get_connector_service)]) –

    The connector service instance.

  • current_user (Annotated[User, Depends(get_current_admin)]) –

    The currently authenticated admin user.

Returns:

  • ConnectorResponse ( ConnectorResponse ) –

    The connector being stopped.

Source code in app/api/v1/endpoints/connectors.py
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
@router.post("/{connector_id}/stop", response_model=ConnectorResponse)
async def stop_connector(
    connector_id: UUID,
    service: Annotated[ConnectorService, Depends(get_connector_service)],
    current_user: Annotated[User, Depends(get_current_admin)],
) -> ConnectorResponse:
    """
    Request to stop a running connector sync.

    Args:
        connector_id: The ID of the connector to stop.
        service: The connector service instance.
        current_user: The currently authenticated admin user.

    Returns:
        ConnectorResponse: The connector being stopped.
    """
    return await service.stop_connector(connector_id)

stop_document(connector_id, document_id, service, current_user) async

Request to stop re-sync for a single document.

Parameters:

  • connector_id (UUID) –

    The ID of the connector.

  • document_id (UUID) –

    The ID of the document to stop.

  • service (Annotated[DocumentService, Depends(get_document_service)]) –

    The document service instance.

  • current_user (Annotated[User, Depends(get_current_admin)]) –

    The currently authenticated admin user.

Returns:

  • Dict[str, str]

    Dict[str, str]: A success message.

Source code in app/api/v1/endpoints/connectors.py
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
@router.post("/{connector_id}/documents/{document_id}/stop")
async def stop_document(
    connector_id: UUID,
    document_id: UUID,
    service: Annotated[DocumentService, Depends(get_document_service)],
    current_user: Annotated[User, Depends(get_current_admin)],
) -> Dict[str, str]:
    """
    Request to stop re-sync for a single document.

    Args:
        connector_id: The ID of the connector.
        document_id: The ID of the document to stop.
        service: The document service instance.
        current_user: The currently authenticated admin user.

    Returns:
        Dict[str, str]: A success message.
    """
    await service.stop_document(document_id)
    return {"message": "Document sync stop requested"}

sync_connector(connector_id, service, current_user, manager=Depends(get_websocket), force=False) async

Trigger manual synchronization for a connector.

Parameters:

  • connector_id (UUID) –

    The ID of the connector to sync.

  • service (Annotated[ConnectorService, Depends(get_connector_service)]) –

    The connector service instance.

  • current_user (Annotated[User, Depends(get_current_admin)]) –

    The currently authenticated admin user.

  • force (bool, default: False ) –

    Whether to force synchronization.

Returns:

  • ConnectorResponse ( ConnectorResponse ) –

    The connector being synced.

Source code in app/api/v1/endpoints/connectors.py
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
@router.post("/{connector_id}/sync", response_model=ConnectorResponse)
async def sync_connector(
    connector_id: UUID,
    service: Annotated[ConnectorService, Depends(get_connector_service)],
    current_user: Annotated[User, Depends(get_current_admin)],
    manager: Websocket = Depends(get_websocket),
    force: bool = False,
) -> ConnectorResponse:
    """
    Trigger manual synchronization for a connector.

    Args:
        connector_id: The ID of the connector to sync.
        service: The connector service instance.
        current_user: The currently authenticated admin user.
        force: Whether to force synchronization.

    Returns:
        ConnectorResponse: The connector being synced.
    """
    connector = await service.trigger_sync(connector_id, force)
    await manager.emit_trigger_connector_sync(str(connector_id))
    return connector

sync_document(connector_id, document_id, service, current_user) async

Trigger re-sync for a single document.

Parameters:

  • connector_id (UUID) –

    The ID of the connector.

  • document_id (UUID) –

    The ID of the document to sync.

  • service (Annotated[DocumentService, Depends(get_document_service)]) –

    The document service instance.

  • current_user (Annotated[User, Depends(get_current_admin)]) –

    The currently authenticated admin user.

Returns:

  • Dict[str, str]

    Dict[str, str]: A success message.

Source code in app/api/v1/endpoints/connectors.py
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
@router.post("/{connector_id}/documents/{document_id}/sync")
async def sync_document(
    connector_id: UUID,
    document_id: UUID,
    service: Annotated[DocumentService, Depends(get_document_service)],
    current_user: Annotated[User, Depends(get_current_admin)],
) -> Dict[str, str]:
    """
    Trigger re-sync for a single document.

    Args:
        connector_id: The ID of the connector.
        document_id: The ID of the document to sync.
        service: The document service instance.
        current_user: The currently authenticated admin user.

    Returns:
        Dict[str, str]: A success message.
    """
    await service.sync_document(document_id)
    return {"message": "Document sync queued"}

test_connection(payload, service, sql_discovery_service, current_user) async

Test a connector connection (primarily for SQL).

Parameters:

  • payload (ConnectorTestConnection) –

    Connection test data.

  • service (Annotated[ConnectorService, Depends(get_connector_service)]) –

    The connector service instance.

  • sql_discovery_service (Annotated[Any, Depends(get_sql_discovery_service)]) –

    The SQL discovery service instance.

  • current_user (Annotated[User, Depends(get_current_admin)]) –

    The currently authenticated admin user.

Returns:

  • Dict[str, Any]

    Dict[str, Any]: A success status and message.

Source code in app/api/v1/endpoints/connectors.py
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
@router.post("/test-connection")
async def test_connection(
    payload: ConnectorTestConnection,
    service: Annotated[ConnectorService, Depends(get_connector_service)],
    sql_discovery_service: Annotated[Any, Depends(get_sql_discovery_service)],
    current_user: Annotated[User, Depends(get_current_admin)],
) -> Dict[str, Any]:
    """
    Test a connector connection (primarily for SQL).

    Args:
        payload: Connection test data.
        service: The connector service instance.
        sql_discovery_service: The SQL discovery service instance.
        current_user: The currently authenticated admin user.

    Returns:
        Dict[str, Any]: A success status and message.
    """
    connector_type = payload.connector_type
    configuration = payload.configuration

    if connector_type in ["sql", "vanna_sql"]:
        try:
            await sql_discovery_service.test_connection(configuration)
            return {"success": True, "message": "Connection successful"}
        except Exception as e:
            logger.error("Connection test failed for %s: %s", connector_type, e)
            return {"success": False, "message": str(e)}

    # Add other types if needed
    return {"success": False, "message": f"Connection test not implemented for {connector_type}"}

train_vanna_connector(connector_id, payload, service, document_service, current_user) async

Train Vanna AI on specific documents (tables/views) for vanna_sql connector.

Parameters:

  • connector_id (UUID) –

    The ID of the connector.

  • payload (ConnectorVannaTrain) –

    Training payload containing document_ids.

  • service (Annotated[ConnectorService, Depends(get_connector_service)]) –

    The connector service instance.

  • document_service (Annotated[DocumentService, Depends(get_document_service)]) –

    The document service instance.

  • current_user (Annotated[User, Depends(get_current_admin)]) –

    The currently authenticated admin user.

Returns:

  • Dict[str, Any]

    Dict[str, Any]: A summary of the training results.

Source code in app/api/v1/endpoints/connectors.py
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
@router.post("/{connector_id}/train")
async def train_vanna_connector(
    connector_id: UUID,
    payload: ConnectorVannaTrain,
    service: Annotated[ConnectorService, Depends(get_connector_service)],
    document_service: Annotated[DocumentService, Depends(get_document_service)],
    current_user: Annotated[User, Depends(get_current_admin)],
) -> Dict[str, Any]:
    """
    Train Vanna AI on specific documents (tables/views) for vanna_sql connector.

    Args:
        connector_id: The ID of the connector.
        payload: Training payload containing `document_ids`.
        service: The connector service instance.
        document_service: The document service instance.
        current_user: The currently authenticated admin user.

    Returns:
        Dict[str, Any]: A summary of the training results.
    """
    return await service.train_vanna(connector_id, payload.document_ids, document_service)

update_connector(connector_id, connector, service, current_user) async

Update an existing connector.

Parameters:

  • connector_id (UUID) –

    The ID of the connector to update.

  • connector (ConnectorUpdate) –

    The connector update data.

  • service (Annotated[ConnectorService, Depends(get_connector_service)]) –

    The connector service instance.

  • current_user (Annotated[User, Depends(get_current_admin)]) –

    The currently authenticated admin user.

Returns:

  • ConnectorResponse ( ConnectorResponse ) –

    The updated connector.

Source code in app/api/v1/endpoints/connectors.py
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
@router.put("/{connector_id}", response_model=ConnectorResponse)
async def update_connector(
    connector_id: UUID,
    connector: ConnectorUpdate,
    service: Annotated[ConnectorService, Depends(get_connector_service)],
    current_user: Annotated[User, Depends(get_current_admin)],
) -> ConnectorResponse:
    """
    Update an existing connector.

    Args:
        connector_id: The ID of the connector to update.
        connector: The connector update data.
        service: The connector service instance.
        current_user: The currently authenticated admin user.

    Returns:
        ConnectorResponse: The updated connector.
    """
    return await service.update_connector(connector_id, connector)

update_document(connector_id, document_id, document, service, current_user) async

Update a specific document.

Parameters:

  • connector_id (UUID) –

    The ID of the connector.

  • document_id (UUID) –

    The ID of the document to update.

  • document (ConnectorDocumentUpdate) –

    The document update data.

  • service (Annotated[DocumentService, Depends(get_document_service)]) –

    The document service instance.

  • current_user (Annotated[User, Depends(get_current_admin)]) –

    The currently authenticated admin user.

Returns:

  • ConnectorDocumentResponse ( ConnectorDocumentResponse ) –

    The updated document.

Source code in app/api/v1/endpoints/connectors.py
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
@router.put("/{connector_id}/documents/{document_id}", response_model=ConnectorDocumentResponse)
async def update_document(
    connector_id: UUID,
    document_id: UUID,
    document: ConnectorDocumentUpdate,
    service: Annotated[DocumentService, Depends(get_document_service)],
    current_user: Annotated[User, Depends(get_current_admin)],
) -> ConnectorDocumentResponse:
    """
    Update a specific document.

    Args:
        connector_id: The ID of the connector.
        document_id: The ID of the document to update.
        document: The document update data.
        service: The document service instance.
        current_user: The currently authenticated admin user.

    Returns:
        ConnectorDocumentResponse: The updated document.
    """
    return await service.update_document(document_id, document)