Running Weaviate on Red Hat Openshift
- Openshift (v4.13.6)
helm
(v3.8.1)- A workstation to run the
oc
andhelm
command line tools.
-
Install the
oc
andhelm
programs on your client workstation. -
Login to Openshift and create a new project with a unique name. If you are using the Developer Sandbox for Red Hat Openshift a project will already exist.
To check for the existence of a project run oc project
, otherwise use oc new-project
to create one.
oc new-project weaviate-bk
PROJ=`oc project -q`
- Begin by reviewing the Weaviate Kubernetes Installation docs. As a quick start, use the example helm chart values file in this repo.
- Configuration options
- Set your desired api keys by renaming the default values in the example
values.yaml
file. See lines 153 - 154. - You may want to increase the storage
size
to something larger. See line 88. - This example
values.yaml
enables the following sections:apikey
text2vec-huggingface
generative-openai
- Set your desired api keys by renaming the default values in the example
- Configure and run the helm installer and wait for the weaviate pod to become ready.
- Add the weaviate repo to the helm configuration.
helm repo add weaviate https://weaviate.github.io/weaviate-helm
- Install Weaviate
helm upgrade --install weaviate weaviate/weaviate --namespace ${PROJ} --values ./values.yaml
- Expose the Weaviate service as a route
oc create route edge weaviate --service=weaviate --insecure-policy='Redirect'
export WEAVIATE_URL=https://$(oc get routes weaviate -n ${PROJ} -o jsonpath='{.spec.host}')
curl ${WEAVIATE_URL}
Sample output
{
"links": {
"href": "/v1",
"name": "api v1",
"documentationHref": "https://weaviate.io/developers/weaviate/current/"
}
}
- Create a python virtual environment and try a few of the example clients. The first two python examples expect the
WEAVIATE_URL
andWEAVIATE_API_KEY
variables to be set.
python -m venv ~/venv
source ~/venv/bin/activate
cd src
pip install -r requirements.txt
export WEAVIATE_URL=https://$(oc get routes weaviate -n ${PROJ} -o jsonpath='{.spec.host}')
export WEAVIATE_API_KEY='weaviate-api-key-from-values-file-above'
- Test the connection with the python sdk.
python 00-test-connection.py
A shard should be reported for each Weaviate node.
Sample output:
INFO:root:{'batchStats': {'queueLength': 0, 'ratePerSecond': 0}, 'gitHash': '8172acb', 'name': 'weaviate-0', 'shards': None, 'stats': {'objectCount': 0, 'shardCount': 0}, 'status': 'HEALTHY', 'version': '1.21.0'}
INFO:root:
INFO:root:{'batchStats': {'queueLength': 0, 'ratePerSecond': 0}, 'gitHash': '8172acb', 'name': 'weaviate-1', 'shards': None, 'stats': {'objectCount': 0, 'shardCount': 0}, 'status': 'HEALTHY', 'version': '1.21.0'}
INFO:root:
INFO:root:{'batchStats': {'queueLength': 0, 'ratePerSecond': 0}, 'gitHash': '8172acb', 'name': 'weaviate-2', 'shards': None, 'stats': {'objectCount': 0, 'shardCount': 0}, 'status': 'HEALTHY', 'version': '1.21.0'}
INFO:root:
- Create a schema and import some objects.
This example requires a HuggingFace api token to create vectors.
export HUGGINGFACE_API_KEY=your-huggingface-api-key
python 01-create-schema-import-data.py
The first time running may produce the following error if the huggingface transformer model is not quite ready.
{'error': [{'message': 'update vector: failed with status: 503 error: Model sentence-transformers/msmarco-bert-base-dot-v5 is currently loading estimated time: 20'}]}
Sample output:
WEAVIATE_URL: https://weaviate-weaviate.apps.ocp.sandbox1234.openshift.com
WEAVIATE_URL: https://weaviate-weaviate.apps.ocp.sandbox1234.openshift.com is_ready() = True
Creating a class using the text2vec-huggingface vectorizer.
Question class already exists, skipping
importing question: 1
importing question: 2
...
- Perform a semantic search.
python 02-semantic-search.py
- Perform a retrieval augmented generative search.
This generative AI example requires an OpenAI API token.
export OPENAI_API_KEY=my_openai_api_key
python 03-generative-search.py
- Run the Gradio front end application example and visit the port reported with a web browser.
python 05-gradio
- Use the Weaviate Cloud Console to make GraphQL queries.
- Add an Openshift route for your external cluster.
- Navigate to the query editor and configure the header.
{
"Authorization" : "Bearer my-weaviate-api-key",
"X-HuggingFace-Api-Key" : "my-huggingface-api-key"
}
- Enter the following sample GraphQL:
{
Get {
Question (
nearText: {
concepts: ["World history"]
}
limit: 2
) {
question
_additional {
generate(
singleResult: {
prompt: """
Convert the following into a question for twitter. Include emojis for fun, but do not include the answer: {question}.
"""
}
) {
singleResult
error
}
}
}
}
}
- Delete the schema if necessary.
python 04-delete-schema.py