Creating and Deploying a Connector
This section will provide a rough guide for implementing a connector. There are two major parts of this process:
- Set up the connector and underlying data source, which requires:
- Configuring the connection between the connector and the data source
- Configuring the connection between the connector and the Chat API
- Deploying the connector
- Register and use your connector with Cohere to get grounded generations
We highly recommend using one of the authentication and authorization methods outlined in our “Connector Authentication” section.
Step 1: Set up the Connector and Data Source
Configure the connection between the connector and the data source:
The connector acts as a proxy between Chat API and the data source. The first step is to configure it to be able to connect to and search the underlying data source. Linking the connector with the data source typically requires setting up a service account in the data source, configuring the service account’s permissions, and copying appropriate credentials into the connector’s environment.
We have provided helpful example skeleton code in this github repository. Each of the quickstart connectors contains a detailed description of the necessary configuration in their README file. The skeleton code is a small example of how to connect to the data source. You will have to edit the code to make it applicable for your situation. You may, for example, customize the exact search query to better suit your needs.
The quickstart connector for Google Drive, for example, requires you to create an “application” in the Google Cloud Console and copy variables into the connector’s environment, like so:
Configure the connection between the connector and the Chat API
Once the connection between the connector and the data source is configured you will need to ensure the response and response structure of the service is compatible with the Chat API. The connector must also respond within 30 seconds for the results to be used in the final generation.
The request from the Chat API to the connector is a POST request that accepts a single query
parameter in the body. The request URL must end with /search
and contain no query parameters, like so:
The response from the connector should be a JSON object with a list of documents in the result field, like so:
Document Structure Recommendations
The structure of the object in the results field is fully flexible, meaning any fields are allowed. However, we strongly recommend the following to improve the final generations:
- Keep documents under 300 words or less. Or add a
text
field which is the field that is truncated whenprompt_truncation=true
in the request. - Add a
timestamp
field to support temporal user queries. - Add an
id
field to allow identification of the relevant document. - Add a
title
field to allow the citations returned in the reply to be better-formatted. - Use
excludes
to exclude fields, such as theid
, from the prompt. - Add a
url
field to allow the client to link to the document.
More details can be found in the documentation for chat.
Deploy the Connector
After the connector and data source are configured correctly, you will need to deploy the connector in a place that Cohere’s API can reach it. For now, this means an internet-facing service. It is important that you can provide Cohere with a URL to send a request to.
Once deployed, ensure that the connector can respond to requests from outside your network. Use the URL at which you made the connector available to register it with Cohere.
Step 2: Register and use your Connector with Cohere
After you’ve deployed the connector and verified it can respond to requests, it is time to register the connector with Cohere. You can do so by sending the following POST request to our API. You will need a Cohere API key, which you can generate here. Here’s an example request and related response:
Make note of the id
, as you will need it when you want to use it later to ground model-generated responses.
During registration, the API will attempt to query the connector to verify that it works as expected. If this step fails, ensure that the connector can respond to requests from outside your network, like so:
Use your Connector with the Chat API
In order to produce grounded generations, include your connector id in the connectors
field in your chat request. Heres an example:
And here’s an example response: