OpenAI Embedding Example
March 22, 2024 ยท View on GitHub
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:
Jupyter Notebook
Notebook: example.ipynb
Try it in the Google colab.
Run in Local
Create a virtual environment
python3 -m venv .venv
source .venv/bin/activate
Install the requirements
pip install -r requirements.txt
Set the environment variables
Get 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="****"
Run the example
python3 example.py