Skip to content

brakmic/Weaviate_with_OpenAI

Repository files navigation

OpenAI experiments with Weaviate - Turnkey Edition

Motivation

I just needed a simple AI container where I could fire up a vector database, connect to OpenAI and (re)create schemas and objects without caring much about anything else. And I wanted it to support languages like Python, JavaScript etc.

Basically: Clone it, install packages, and have fun with it. :)

Requirements

Setup

  • Install python 3 for your OS
  • Install pipenv with pip install --user pipenv
  • Initialize pipenv in cloned repo with pipenv --python3
  • Start python env with pipenv shell
  • Install python packages weaviate-client and requests with pip3 install PKG_NAME
  • Generate an OpenAI API Key
  • Add this key to local shell. By default the variable must be called OPENAI_APIKEY
  • Optionally, reconfigure docker-compose.yml to use additional plugins from Weaviate
  • Start container with podman-compose up -d or docker-compose up -d

This is how the running container should look like.

podman1

podman2

Using Weaviate with OpenAI

You should see something like this:

schema1

Also check objects unter http://localhost:8080/v1/objects

objects1

Now query for some of those objects by using executing python query_engine.py. You should get these results back:

query1

As Weaviate also supports GraphQL you could use Apollo GraphQL Explorer to send queries.

Just enter http://localhost:8080/v1/graphql into the sandbox field.

graphql1

Docker Compose

The default docker-compose.yml from this repo looks like this.

---
version: '3.4'
services:
  weaviate:
    command:
    - --host
    - 0.0.0.0
    - --port
    - '8080'
    - --scheme
    - http
    image: semitechnologies/weaviate:1.18.1
    ports:
    - 8080:8080
    restart: on-failure:0
    volumes:
    - weaviate_local:/var/lib/weaviate   # mapping volume to keep schema, otherwise it'd be deleted after restart 
    environment:
      OPENAI_APIKEY: $OPENAI_APIKEY        # OpenAI API key must be present as shell variable: `echo $OPENAI_APIKEY`
      QUERY_DEFAULTS_LIMIT: 25
      AUTHENTICATION_ANONYMOUS_ACCESS_ENABLED: 'true'
      PERSISTENCE_DATA_PATH: '/var/lib/weaviate'
      DEFAULT_VECTORIZER_MODULE: 'text2vec-openai'
      ENABLE_MODULES: 'text2vec-openai'
      CLUSTER_HOSTNAME: 'node1'
...

License

MIT

Releases

No releases published

Packages

No packages published

Languages