A connector lets a language model access external data, such as web search or databases. By grounding answers in retrieved information, it can reduce unsupported claims and expose sources readers can check. section 8.2
Connectors can be used in two practical ways:
- Toggle the web connector in Cohere’s interface to compare answers to factual questions with web access on or off. section 8.2.1
- Pass a list of connectors to Cohere’s Python chat call; the example uses the web-search connector. section 8.2.2
Check an answer against web results
Ask where Steve Jobs was born. The response includes an answer, search queries, retrieved snippets, and URLs, so you can check whether the sources support the answer. section 8.2.2
Listing 8.2 Answering questions using Cohere’s Python library
import argparse
import cohere
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument('ai_key', type=str, help='Cohere access key')
parser.add_argument('question', type=str, help='Answer this question')
args = parser.parse_args()
client = cohere.Client(args.ai_key) #1
#2
prompt = f'Answer this question: {args.question}'
result = client.chat(prompt, connectors=[{'id': 'web-search'}])
#3
print(f'Answer: result.text')
print(f'Web searches: result.search_results')
print(f'Web results: result.documents')
See a Python example that passes the web-search connector and prints the answer and retrieved sources. section 8.2.2






