Skip to content

Commit

Permalink
Use surrealist mini stable URLs (#801)
Browse files Browse the repository at this point in the history
  • Loading branch information
macjuul authored Aug 31, 2024
1 parent 9e704fa commit 93d826d
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ Let's now create a blog article record, which links to the `author` and `account


<SurrealistMini
url="https://dev.surrealist.app/mini?setup=CREATE+account+SET%0A%09name+%3D+%27ACME+Inc%27%2C%0A%09created_at+%3D+time%3A%3Anow%28%29%0A%3B%0ACREATE+author%3Ajohn+SET%0A%09name.first+%3D+%27John%27%2C%0A%09name.last+%3D+%27Adams%27%2C%0A%09name.full+%3D+string%3A%3Ajoin%28%27+%27%2C+name.first%2C+name.last%29%2C%0A%09age+%3D+29%2C%0A%09admin+%3D+true%2C%0A%09signup_at+%3D+time%3A%3Anow%28%29%0A%3B%0A&query=CREATE+article+SET%0A%09created_at+%3D+time%3A%3Anow%28%29%2C%0A%09author+%3D+author%3Ajohn%2C%0A%09title+%3D+%27Lorem+ipsum+dolor%27%2C%0A%09text+%3D+%27Donec+eleifend%2C+nunc+vitae+commodo+accumsan%2C+mauris+est+fringilla.%27%2C%0A%09account+%3D+%28SELECT+VALUE+id+FROM+account+WHERE+name+%3D+%27ACME+Inc%27+LIMIT+1%29%5B0%5D%0A%3B"
url="https://surrealist.app/mini?setup=CREATE+account+SET%0A%09name+%3D+%27ACME+Inc%27%2C%0A%09created_at+%3D+time%3A%3Anow%28%29%0A%3B%0ACREATE+author%3Ajohn+SET%0A%09name.first+%3D+%27John%27%2C%0A%09name.last+%3D+%27Adams%27%2C%0A%09name.full+%3D+string%3A%3Ajoin%28%27+%27%2C+name.first%2C+name.last%29%2C%0A%09age+%3D+29%2C%0A%09admin+%3D+true%2C%0A%09signup_at+%3D+time%3A%3Anow%28%29%0A%3B%0A&query=CREATE+article+SET%0A%09created_at+%3D+time%3A%3Anow%28%29%2C%0A%09author+%3D+author%3Ajohn%2C%0A%09title+%3D+%27Lorem+ipsum+dolor%27%2C%0A%09text+%3D+%27Donec+eleifend%2C+nunc+vitae+commodo+accumsan%2C+mauris+est+fringilla.%27%2C%0A%09account+%3D+%28SELECT+VALUE+id+FROM+account+WHERE+name+%3D+%27ACME+Inc%27+LIMIT+1%29%5B0%5D%0A%3B"
/>

### Querying data with [`SELECT`](/docs/surrealdb/surrealql/statements/select)
Expand All @@ -139,14 +139,14 @@ Also, in SurrealDB we can retrieve data from multiple different tables or record
SELECT * FROM article, account;
```

<SurrealistMini url= "https://dev.surrealist.app/mini?setup=CREATE+account+SET%0A%09name+%3D+%27ACME+Inc%27%2C%0A%09created_at+%3D+time%3A%3Anow%28%29%0A%3B%0ACREATE+author%3Ajohn+SET%0A%09name.first+%3D+%27John%27%2C%0A%09name.last+%3D+%27Adams%27%2C%0A%09name.full+%3D+string%3A%3Ajoin%28%27+%27%2C+name.first%2C+name.last%29%2C%0A%09age+%3D+29%2C%0A%09admin+%3D+true%2C%0A%09signup_at+%3D+time%3A%3Anow%28%29%3B%0A%0ACREATE+article+SET%0A%09created_at+%3D+time%3A%3Anow%28%29%2C%0A%09author+%3D+author%3Ajohn%2C%0A%09title+%3D+%27Lorem+ipsum+dolor%27%2C%0A%09text+%3D+%27Donec+eleifend%2C+nunc+vitae+commodo+accumsan%2C+mauris+est+fringilla.%27%2C%0A%09account+%3D+%28SELECT+VALUE+id+FROM+account+WHERE+name+%3D+%27ACME+Inc%27+LIMIT+1%29%5B0%5D%0A%3B%0A%0A&query=SELECT+*+FROM+article%2C+account%3B" />
<SurrealistMini url= "https://surrealist.app/mini?setup=CREATE+account+SET%0A%09name+%3D+%27ACME+Inc%27%2C%0A%09created_at+%3D+time%3A%3Anow%28%29%0A%3B%0ACREATE+author%3Ajohn+SET%0A%09name.first+%3D+%27John%27%2C%0A%09name.last+%3D+%27Adams%27%2C%0A%09name.full+%3D+string%3A%3Ajoin%28%27+%27%2C+name.first%2C+name.last%29%2C%0A%09age+%3D+29%2C%0A%09admin+%3D+true%2C%0A%09signup_at+%3D+time%3A%3Anow%28%29%3B%0A%0ACREATE+article+SET%0A%09created_at+%3D+time%3A%3Anow%28%29%2C%0A%09author+%3D+author%3Ajohn%2C%0A%09title+%3D+%27Lorem+ipsum+dolor%27%2C%0A%09text+%3D+%27Donec+eleifend%2C+nunc+vitae+commodo+accumsan%2C+mauris+est+fringilla.%27%2C%0A%09account+%3D+%28SELECT+VALUE+id+FROM+account+WHERE+name+%3D+%27ACME+Inc%27+LIMIT+1%29%5B0%5D%0A%3B%0A%0A&query=SELECT+*+FROM+article%2C+account%3B" />

Also, instead of pulling data from multiple tables and merging that data together, SurrealDB allows you to traverse related records efficiently without needing to use JOINs. In the following example, we will get all the articles where the author is younger than 30. In order to get the information for the author age for our filter condition we need to fetch the relevant records from the author table.

```surql
SELECT * FROM article WHERE author.age < 30 FETCH author, account;
```
<SurrealistMini url="https://dev.surrealist.app/mini?setup=CREATE+account+SET%0A%09name+%3D+%27ACME+Inc%27%2C%0A%09created_at+%3D+time%3A%3Anow%28%29%0A%3B%0ACREATE+author%3Ajohn+SET%0A%09name.first+%3D+%27John%27%2C%0A%09name.last+%3D+%27Adams%27%2C%0A%09name.full+%3D+string%3A%3Ajoin%28%27+%27%2C+name.first%2C+name.last%29%2C%0A%09age+%3D+29%2C%0A%09admin+%3D+true%2C%0A%09signup_at+%3D+time%3A%3Anow%28%29%3B%0A%0ACREATE+article+SET%0A%09created_at+%3D+time%3A%3Anow%28%29%2C%0A%09author+%3D+author%3Ajohn%2C%0A%09title+%3D+%27Lorem+ipsum+dolor%27%2C%0A%09text+%3D+%27Donec+eleifend%2C+nunc+vitae+commodo+accumsan%2C+mauris+est+fringilla.%27%2C%0A%09account+%3D+%28SELECT+VALUE+id+FROM+account+WHERE+name+%3D+%27ACME+Inc%27+LIMIT+1%29%5B0%5D%0A%3B%0A&query=SELECT+*+FROM+article+WHERE+author.age+%3C+30+FETCH+author%2C+account%3B" />
<SurrealistMini url="https://surrealist.app/mini?setup=CREATE+account+SET%0A%09name+%3D+%27ACME+Inc%27%2C%0A%09created_at+%3D+time%3A%3Anow%28%29%0A%3B%0ACREATE+author%3Ajohn+SET%0A%09name.first+%3D+%27John%27%2C%0A%09name.last+%3D+%27Adams%27%2C%0A%09name.full+%3D+string%3A%3Ajoin%28%27+%27%2C+name.first%2C+name.last%29%2C%0A%09age+%3D+29%2C%0A%09admin+%3D+true%2C%0A%09signup_at+%3D+time%3A%3Anow%28%29%3B%0A%0ACREATE+article+SET%0A%09created_at+%3D+time%3A%3Anow%28%29%2C%0A%09author+%3D+author%3Ajohn%2C%0A%09title+%3D+%27Lorem+ipsum+dolor%27%2C%0A%09text+%3D+%27Donec+eleifend%2C+nunc+vitae+commodo+accumsan%2C+mauris+est+fringilla.%27%2C%0A%09account+%3D+%28SELECT+VALUE+id+FROM+account+WHERE+name+%3D+%27ACME+Inc%27+LIMIT+1%29%5B0%5D%0A%3B%0A&query=SELECT+*+FROM+article+WHERE+author.age+%3C+30+FETCH+author%2C+account%3B" />

### [`UPDATE`](/docs/surrealdb/surrealql/statements/update)

Expand All @@ -156,7 +156,7 @@ Similar to [UPDATE](/docs/surrealdb/surrealql/statements/update) in SQL you can
UPDATE author:john SET name.first = 'David', name.full = string::join(' ', name.first, name.last);
```

<SurrealistMini url="https://dev.surrealist.app/mini?setup=CREATE+author%3Ajohn+SET%0A%09name.first+%3D+%27John%27%2C%0A%09name.last+%3D+%27Adams%27%2C%0A%09name.full+%3D+string%3A%3Ajoin%28%27+%27%2C+name.first%2C+name.last%29%2C%0A%09age+%3D+29%2C%0A%09admin+%3D+true%2C%0A%09signup_at+%3D+time%3A%3Anow%28%29%3B%0A%0ACREATE+article+SET%0A%09created_at+%3D+time%3A%3Anow%28%29%2C%0A%09author+%3D+author%3Ajohn%2C%0A%09title+%3D+%27Lorem+ipsum+dolor%27%2C%0A%09text+%3D+%27Donec+eleifend%2C+nunc+vitae+commodo+accumsan%2C+mauris+est+fringilla.%27%2C%0A%09account+%3D+%28SELECT+VALUE+id+FROM+account+WHERE+name+%3D+%27ACME+Inc%27+LIMIT+1%29%5B0%5D%0A%3B&query=UPDATE+author%3Ajohn+SET+name.first+%3D+%27David%27%2C+name.full+%3D+string%3A%3Ajoin%28%27+%27%2C+name.first%2C+name.last%29%3B"/>
<SurrealistMini url="https://surrealist.app/mini?setup=CREATE+author%3Ajohn+SET%0A%09name.first+%3D+%27John%27%2C%0A%09name.last+%3D+%27Adams%27%2C%0A%09name.full+%3D+string%3A%3Ajoin%28%27+%27%2C+name.first%2C+name.last%29%2C%0A%09age+%3D+29%2C%0A%09admin+%3D+true%2C%0A%09signup_at+%3D+time%3A%3Anow%28%29%3B%0A%0ACREATE+article+SET%0A%09created_at+%3D+time%3A%3Anow%28%29%2C%0A%09author+%3D+author%3Ajohn%2C%0A%09title+%3D+%27Lorem+ipsum+dolor%27%2C%0A%09text+%3D+%27Donec+eleifend%2C+nunc+vitae+commodo+accumsan%2C+mauris+est+fringilla.%27%2C%0A%09account+%3D+%28SELECT+VALUE+id+FROM+account+WHERE+name+%3D+%27ACME+Inc%27+LIMIT+1%29%5B0%5D%0A%3B&query=UPDATE+author%3Ajohn+SET+name.first+%3D+%27David%27%2C+name.full+%3D+string%3A%3Ajoin%28%27+%27%2C+name.first%2C+name.last%29%3B"/>

The above code will update the firstname to be David and then create a new string for fullname with the updated first and last name.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ In the example below, we have a table called `liquids` with a `sample` field and
Then, using the select statement to retrieve all the samples containing the chemical lead will also bring up samples that mention the word `lead`.

<SurrealistMini
url="https://dev.surrealist.app/mini?query=--+Insert+a+sample+%26+content+field+into+a+liquids+table%0A%0AINSERT+INTO+liquids+%5B%0A++++%7Bsample%3A%27Sea+water%27%2C+content%3A+%27The+sea+water+contains+some+amount+of+lead%27%7D%2C%0A++++%7Bsample%3A%27Tap+water%27%2C+content%3A+%27The+team+lead+by+Dr.+Rose+found+out+that+the+tap+water+in+was+potable%27%7D%2C%0A++++%7Bsample%3A%27Sewage+water%27%2C+content%3A+%27High+amounts+of+a+were+found+in+Sewage+water%27%7D%0A%5D%3B%0A%0A--+Define+an+analyzer+for+the+liquid+table+and+an+index+on+the+content+field+with+the+analyzer%0A%0ADEFINE+ANALYZER+liquid_analyzer+TOKENIZERS+blank%2Cclass%2Ccamel%2Cpunct+FILTERS+snowball%28english%29%3B%0ADEFINE+INDEX+liquid_content+ON+liquids+FIELDS+content+SEARCH+ANALYZER+liquid_analyzer+BM25+HIGHLIGHTS%3B%0A%0A--+Retrieve+all+the+samples+containing+the+chemical+lead+will+also+bring+up+samples+that+simply+mention+the+word+lead%0A%0ASELECT%0A++sample%2C%0A++content%0AFROM+liquids%0AWHERE+content+%400%40+%27lead%27%3B&orientation=horizontal"
url="https://surrealist.app/mini?query=--+Insert+a+sample+%26+content+field+into+a+liquids+table%0A%0AINSERT+INTO+liquids+%5B%0A++++%7Bsample%3A%27Sea+water%27%2C+content%3A+%27The+sea+water+contains+some+amount+of+lead%27%7D%2C%0A++++%7Bsample%3A%27Tap+water%27%2C+content%3A+%27The+team+lead+by+Dr.+Rose+found+out+that+the+tap+water+in+was+potable%27%7D%2C%0A++++%7Bsample%3A%27Sewage+water%27%2C+content%3A+%27High+amounts+of+a+were+found+in+Sewage+water%27%7D%0A%5D%3B%0A%0A--+Define+an+analyzer+for+the+liquid+table+and+an+index+on+the+content+field+with+the+analyzer%0A%0ADEFINE+ANALYZER+liquid_analyzer+TOKENIZERS+blank%2Cclass%2Ccamel%2Cpunct+FILTERS+snowball%28english%29%3B%0ADEFINE+INDEX+liquid_content+ON+liquids+FIELDS+content+SEARCH+ANALYZER+liquid_analyzer+BM25+HIGHLIGHTS%3B%0A%0A--+Retrieve+all+the+samples+containing+the+chemical+lead+will+also+bring+up+samples+that+simply+mention+the+word+lead%0A%0ASELECT%0A++sample%2C%0A++content%0AFROM+liquids%0AWHERE+content+%400%40+%27lead%27%3B&orientation=horizontal"
/>

If you read through the content of the tap water sample, you’ll notice that it does not contain any lead in it but it has the mention of the word `lead` under “The team lead by Dr. Rose…” which means that the team was guided by Dr. Rose.
Expand Down Expand Up @@ -88,7 +88,7 @@ As you want to perform a nearest neighbour search and not an exact search, you w



<SurrealistMini url="https://dev.surrealist.app/mini?setup=--+Insert+a+sample+%26+content+field+into+a+liquids+table%0AINSERT+INTO+liquidsVector+%5B%0A++++%7Bsample%3A%27Sea+water%27%2C+content%3A+%27The+sea+water+contains+some+amount+of+lead%27%2C+embedding%3A+%5B0.1%2C+0.2%2C+0.3%2C+0.4%5D+%7D%2C%0A++++%7Bsample%3A%27Tap+water%27%2C+content%3A+%27The+team+lead+by+Dr.+Rose+found+out+that+the+tap+water+in+was+potable%27%2C+embedding%3A%5B1.0%2C+0.1%2C+0.4%2C+0.3%5D%7D%2C%0A++++%7Bsample%3A%27Sewage+water%27%2C+content%3A+%27High+amounts+of+a+were+found+in+Sewage+water%27%2C+embedding+%3A+%5B0.4%2C+0.3%2C+0.2%2C+0.1%5D%7D%0A%5D%3B&query=--+Add+embeddings+for+what+lead+as+a+harmful+substance+should+be.+%0ALET+%24lead_harmful+%3D+%5B0.15%2C+0.25%2C+0.35%2C+0.45%5D%3B%0A%0A--+Define+a+vector+index+on+the+liquidsVector+table+for+embedding+field+%0ADEFINE+INDEX+mt_pts+ON+liquidsVector+FIELDS+embedding+MTREE+DIMENSION+4+DIST+COSINE+TYPE+F32%3B%0A%0A--+Select+the+sample+and+content+from+the+liquids+table+with+cosine+similarity+%0ASELECT+sample%2C+content%2C+vector%3A%3Asimilarity%3A%3Acosine%28embedding%2C+%24lead_harmful%29+AS+dist+FROM+liquidsVector+WHERE+embedding+%3C%7C2%7C%3E+%24lead_harmful%3B&orientation=horizontal"/>
<SurrealistMini url="https://surrealist.app/mini?setup=--+Insert+a+sample+%26+content+field+into+a+liquids+table%0AINSERT+INTO+liquidsVector+%5B%0A++++%7Bsample%3A%27Sea+water%27%2C+content%3A+%27The+sea+water+contains+some+amount+of+lead%27%2C+embedding%3A+%5B0.1%2C+0.2%2C+0.3%2C+0.4%5D+%7D%2C%0A++++%7Bsample%3A%27Tap+water%27%2C+content%3A+%27The+team+lead+by+Dr.+Rose+found+out+that+the+tap+water+in+was+potable%27%2C+embedding%3A%5B1.0%2C+0.1%2C+0.4%2C+0.3%5D%7D%2C%0A++++%7Bsample%3A%27Sewage+water%27%2C+content%3A+%27High+amounts+of+a+were+found+in+Sewage+water%27%2C+embedding+%3A+%5B0.4%2C+0.3%2C+0.2%2C+0.1%5D%7D%0A%5D%3B&query=--+Add+embeddings+for+what+lead+as+a+harmful+substance+should+be.+%0ALET+%24lead_harmful+%3D+%5B0.15%2C+0.25%2C+0.35%2C+0.45%5D%3B%0A%0A--+Define+a+vector+index+on+the+liquidsVector+table+for+embedding+field+%0ADEFINE+INDEX+mt_pts+ON+liquidsVector+FIELDS+embedding+MTREE+DIMENSION+4+DIST+COSINE+TYPE+F32%3B%0A%0A--+Select+the+sample+and+content+from+the+liquids+table+with+cosine+similarity+%0ASELECT+sample%2C+content%2C+vector%3A%3Asimilarity%3A%3Acosine%28embedding%2C+%24lead_harmful%29+AS+dist+FROM+liquidsVector+WHERE+embedding+%3C%7C2%7C%3E+%24lead_harmful%3B&orientation=horizontal"/>


In the example above you can see that the results are more accurate. The search pulled up only the `Sea water` sample which contains the harmful substance `lead` in it. This is the advantage of using Vector Search over Full-Text Search.
Expand Down
Loading

0 comments on commit 93d826d

Please sign in to comment.