backend/onyx/connectors/README.md
This README covers how to contribute a new Connector for Onyx. It includes an overview of the design, interfaces, and required changes.
Thank you for your contribution!
Connectors come in 3 different flows:
Refer to interfaces.py and this first contributor created Pull Request for a new connector (Shoutout to Dan Brown): Reference Pull Request
For implementing a Slim Connector, refer to the comments in this PR: Slim Connector PR
All new connectors should have tests added to the backend/tests/daily/connectors directory. Refer to the above PR for an example of adding tests for a new connector.
The connector must subclass one or more of LoadConnector, PollConnector, CheckpointedConnector, or CheckpointedConnectorWithPermSync
The __init__ should take arguments for configuring what documents the connector will and where it finds those
documents. For example, if you have a wiki site, it may include the configuration for the team, topic, folder, etc. of
the documents to fetch. It may also include the base domain of the wiki. Alternatively, if all the access information
of the connector is stored in the credential/token, then there may be no required arguments.
load_credentials should take a dictionary which provides all the access information that the connector might need.
For example this could be the user's username and access token.
Refer to the existing connectors for load_from_state and poll_source examples. There is not yet a process to listen
for EventConnector events, this will come down the line.
It may be handy to test your new connector separate from the rest of the stack while developing. Follow the below template:
if __name__ == "__main__":
import time
test_connector = NewConnector(space="engineering")
test_connector.load_credentials({
"user_id": "foobar",
"access_token": "fake_token"
})
all_docs = test_connector.load_from_state()
current = time.time()
one_day_ago = current - 24 * 60 * 60 # 1 day
latest_docs = test_connector.poll_source(one_day_ago, current)
Note: Be sure to set PYTHONPATH to onyx/backend before running the above main.
If the source has attachments (files attached to pages, tickets, etc.), let admins opt out of indexing them by following the shared convention:
include_attachments: bool kwarg in the connector's __init__. The value flows in
automatically from connector_specific_config; no factory or API changes are needed.
False.True — existing connector rows have no include_attachments key stored, so the constructor
default is what they get and their behavior must not change.chunk_count IS NULL rows, while correctly omitting them lets pruning
clean up previously indexed attachments after an admin turns the setting off.buildIncludeAttachmentsOption(<default>) from
web/src/lib/connectors/connectors.tsx to the connector's connectorConfigs entry (use the
same default as the backend), and add include_attachments?: boolean to the connector's config
interface in that file.ConfluenceConnector and DrupalWikiConnector are reference implementations.
SOURCE_METADATA_MAP here.connectorConfigs object here.Create the new connector page (with guiding images!) with how to get the connector credentials and how to set up the connector in Onyx. Then create a Pull Request in https://github.com/onyx-dot-app/documentation.
Add Connector page).backend/tests/daily/connectors director. For an example, checkout the test for Confluence. In the PR description, include a guide on how to setup the new source to pass the test. Before merging, we will re-create the environment and make sure the test(s) pass.