Skip to content

Commit

Permalink
add weaviate tutorial
Browse files Browse the repository at this point in the history
  • Loading branch information
samos123 committed Oct 28, 2023
1 parent c6e5a04 commit f0b3dd1
Show file tree
Hide file tree
Showing 5 changed files with 98 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
.venv
__pycache__
.vscode
26 changes: 26 additions & 0 deletions weaviate/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# STAPI Weaviate Tutorial
A short tutorial that shows easy it is to use STAPI
(Sentence Transformers API)
with Weaviate by using the text2vec-openai module.

## Install: Local Docker Compose
Bring up Weaviate and STAPI:
```bash
docker compose up -d
```

Create the schema that vectorizes using STAPI endpoint:
```
curl -X POST \
-H "Content-Type: application/json" \
-d @schema.json \
http://localhost:8080/v1/schema
```

Create an object in Weaviate and watch the embedding magic happen:
```bash
curl -X POST \
-H "Content-Type: application/json" \
-d @object.json \
http://localhost:8080/v1/objects?consistency_level=ALL
```
37 changes: 37 additions & 0 deletions weaviate/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
---
version: '3.4'
services:
stapi:
image: ghcr.io/substratusai/stapi
environment:
PORT: 8081
MODEL: multi-qa-MiniLM-L6-cos-v1
ports:
- 8081:8081
weaviate:
command:
- --host
- 0.0.0.0
- --port
- '8080'
- --scheme
- http
image: semitechnologies/weaviate:1.22.0
links:
- "stapi:stapi"
ports:
- 8080:8080
volumes:
- weaviate_data:/var/lib/weaviate
restart: on-failure:0
environment:
QUERY_DEFAULTS_LIMIT: 25
AUTHENTICATION_ANONYMOUS_ACCESS_ENABLED: 'true'
PERSISTENCE_DATA_PATH: '/var/lib/weaviate'
OPENAI_APIKEY: "not-needed-for-sentence-transformers-api"
DEFAULT_VECTORIZER_MODULE: 'text2vec-openai'
ENABLE_MODULES: 'text2vec-cohere,text2vec-huggingface,text2vec-palm,text2vec-openai,generative-openai,generative-cohere,generative-palm,ref2vec-centroid,reranker-cohere,qna-openai'
CLUSTER_HOSTNAME: 'node1'
volumes:
weaviate_data:
...
7 changes: 7 additions & 0 deletions weaviate/object.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"class": "Question",
"properties": {
"question": "Who writes the best LLM tools?",
"answer": "substratus.ai ofcourse"
}
}
27 changes: 27 additions & 0 deletions weaviate/schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"class": "Question",
"description": "A class called document",
"vectorizer": "text2vec-openai",
"moduleConfig": {
"text2vec-openai": {
"model": "davinci",
"baseURL": "http://stapi:8081"
}
},
"properties": [
{
"dataType": [
"text"
],
"description": "The question",
"name": "question"
},
{
"dataType": [
"text"
],
"description": "The answer",
"name": "answer"
}
]
}

0 comments on commit f0b3dd1

Please sign in to comment.