visit
is an open-source, GraphQL-based, search graph based on a build in embedding mechanism.Before we get started, some further reading while exploring Weaviate.
{
"title": "African bush elephant",
"photoUrl": "//en.wikipedia.org/wiki/African_bush_elephant"
}
This is the problem the Weaviate search graph solves, because of its build-in natural language model, it indexes your data based on the context rather than keywords alone.In this article, you will learn within 10 minutes how to use Weaviate to build your own semantic search engine and how this GraphQL query:
{
Get{
Things{
Photo(
explore: {
concepts: ["animal with a trunk"]
}
limit:1
){
title
photoUrl
}
}
}
}
{
"data": {
"Get": {
"Things": {
"Photo": [
{
"photoUrl": "//upload.wikimedia.org/wikipedia/commons/b/bf/African_Elephant_%28Loxodonta_africana%29_male_%28%29.jpg",
"title": "African bush elephant"
}
]
}
}
},
"errors": null
}
# Download the Weaviate configuration file
$ curl -O //raw.githubusercontent.com/semi-technologies/weaviate/0.22.7/docker-compose/runtime/en/config.yaml
# Download the Weaviate docker-compose file
$ curl -O //raw.githubusercontent.com/semi-technologies/weaviate/0.22.7/docker-compose/runtime/en/docker-compose.yml
# Run Docker Compose
$ docker-compose up
$ curl //localhost:8080/v1/meta
$ curl \
--header "Content-Type: application/json" \
--request POST \
--data '{
"class": "Photo",
"description": "A photo",
"vectorizeClassName": false,
"keywords": [],
"properties": [
{
"dataType": [
"string"
],
"name": "title",
"description": "Title of the Photo",
"vectorizePropertyName": false,
"index": true
}, {
"dataType": [
"string"
],
"name": "photoUrl",
"description": "URL of the Photo",
"vectorizePropertyName": false,
"index": false
}
]
}' \
//localhost:8080/v1/schema/things
$ curl //localhost:8080/v1/schema
# or with jq
$ curl //localhost:8080/v1/schema | jq .
$ curl \
--header "Content-Type: application/json" \
--request POST \
--data '{
"class": "User",
"description": "A user",
"keywords": [],
"properties": [
{
"dataType": [
"string"
],
"name": "name",
"description": "Name of the user"
}, {
"dataType": [
"Photo"
],
"name": "ownsPhotos",
"description": "Photos this user owns",
"cardinality": "many"
}
]
}' \
//localhost:8080/v1/schema/things
# Add the elephant
$ curl \
--header "Content-Type: application/json" \
--request POST \
--data '{
"class": "Photo",
"schema": {
"title": "African bush elephant",
"photoUrl": "//upload.wikimedia.org/wikipedia/commons/b/bf/African_Elephant_%28Loxodonta_africana%29_male_%28%29.jpg"
}
}' \
//localhost:8080/v1/things
# Add Brad Pitt
$ curl \
--header "Content-Type: application/json" \
--request POST \
--data '{
"class": "Photo",
"schema": {
"title": "Brad Pitt at the 2019 premiere of Once Upon a Time in Hollywood",
"photoUrl": "//upload.wikimedia.org/wikipedia/commons/4/4c/Brad_Pitt_2019_by_Glenn_Francis.jpg"
}
}' \
//localhost:8080/v1/things
# First, add the user
$ curl \
--header "Content-Type: application/json" \
--request POST \
--data '{
"class": "User",
"schema": {
"name": "John Doe"
}
}' \
//localhost:8080/v1/things
$ curl \
--header "Content-Type: application/json" \
--request PUT \
--data '[{
"beacon": "weaviate://localhost/things/b81e530f-f8db-41b6-910f-0469c8b7884e"
}, {
"beacon": "weaviate://localhost/things/127c8bcb-99bf-4c8d-94d4-f67cd2323548"
}]' \
//localhost:8080/v1/things/0b70b628-377b-4b4d-85c8-89b0dacd4209/references/ownsPhotos
$ curl //localhost:8080/v1/things
# or with jq
$ curl //localhost:8080/v1/things | jq .
Now that we have all data in, we are getting to the juicy part of Weaviate, search. Searching is done with . You can learn more about all the possible functions or you can get into the nitty-gritty details of the Weaviate GraphQL API by reading this Hackernoon article.
But for now, we are going to keep it simple.You can use any GraphQL client you like, but to play around with the available queries, you can use the . If you go to the Playground, fill in //localhost:8080/v1/graphql as the location and click “GraphQL Querying” in the right-hand corner.
To find the photo of the elephant you can do the following:{
Get{
Things{
Photo(
explore: {
concepts: ["animal"]
}
limit:1
){
title
photoUrl
}
}
}
}
{
Get{
Things{
Photo(
explore: {
concepts: ["actor"]
}
limit:1
){
title
photoUrl
}
}
}
}
{
Get{
Things{
Photo(
explore: {
concepts: ["angelina", "jolie"]
}
limit:1
){
title
photoUrl
}
}
}
}