

Connect to Weaviate DB:
https://cohere-demo.weaviate.network/) contains 10 million records from Wikipedia.
import weaviate
auth_config = weaviate.auth.AuthApiKey(
api_key=os.environ['WEAVIATE_API_KEY'])
#WEAVIATE_API_KEY="76320a90-53d8-42bc-b41d-678647c6672e"
client = weaviate.Client(
url=os.environ['WEAVIATE_API_URL'], # the public DB for this course: <https://cohere-demo.weaviate.network/>
auth_client_secret=auth_config,
additional_headers={
"X-Cohere-Api-Key": os.environ['COHERE_API_KEY'],
}
)
client.is_ready()
bm25 → it’s a keyword (lexical) search algorithm commonly used, and it scores the documents in the DB against the query based on specific formula that looks at the count of the shared words between the query and each document. Read moredef keyword_search(query,
results_lang='en',
properties = ["title","url","text"],
num_results=3):
where_filter = {
"path": ["lang"],
"operator": "Equal",
"valueString": results_lang
}
# Calling Weaviate API
response = (
client.query.get("Articles", properties)
.with_bm25(
query=query
)
.with_where(where_filter)
.with_limit(num_results)
.do()
)
result = response['data']['Get']['Articles']
return result
query = "What is the most viewed televised event?"
keyword_search_results = keyword_search(query)
print(keyword_search_results)