This example demonstrates how to utilize OpenAI embedding for semantic search. According to OpenAI's documentation, we will use cosine similarity to calculate vector distance.
You can run this example in two ways:
Notebook: example.ipynb
Try it in the Google colab.
python3 -m venv .venv
source .venv/bin/activatepip install -r requirements.txtGet the OPENAI_API_KEY from OpenAI
Get the TIDB_HOST, TIDB_USERNAME, and TIDB_PASSWORD from the TiDB Cloud console, as described in the Prerequisites section.
export OPENAI_API_KEY="sk-*******"
export TIDB_HOST="gateway01.*******.shared.aws.tidbcloud.com"
export TIDB_USERNAME="****.root"
export TIDB_PASSWORD="****"python3 example.py