You signed in with another tab or window.Reload to refresh your session.You signed out in another tab or window.Reload to refresh your session.You switched accounts on another tab or window.Reload to refresh your session.Dismiss alert
We started PostgresML two years ago with the goal of making machine learning and AI accessible and easy for everyone. To make this a reality, we needed to deploy PostgresML as closely as possible to our end users. With that goal mind, today we're proud to announce support for a new cloud provider: Azure.
Building web apps on top of PostgresML allows anyone to integrate advanced machine learning and AI features into their products without much work or needing to understand how it really works. In this blog post, we'll talk about building a classic to-do Django app, with the spicy addition of semantic search powered by embedding models running inside your PostgreSQL database.
9
20
10
21
###Getting the code
@@ -56,13 +67,14 @@ And that's it! In just a few lines of code, we're generating and storing high qu
56
67
57
68
Djago Rest Framework provides the bulk of the implementation. We just added a`ModelViewSet` for the`TodoItem` model, with just one addition: a search endpoint. The search endpoint required us to write a bit of SQL to embed the search query and accept a few filters, but the core of it can be summarized in a single annotation on the query set:
@@ -76,7 +88,7 @@ All of this happens inside PostgresML. Our Django app doesn't need to implement
76
88
77
89
Before going forward, make sure you have the app running either locally or in a cloud provider of your choice. If hosting it somewhere, replace`localhost:8000` with the URL and port of your service.
78
90
79
-
The simplest way to interact with it is to use cURL oranHTTP client of your preference. If running in debug mode locally, the Rest Framework provides a nice web UI which you can access on[http://localhost:8000/api/todos/](http://localhost:8000/api/todo/) using a browser.
91
+
The simplest way to interact with it is to use cURL oryour preferredHTTP client. If running in debug mode locally, the Rest Framework provides a nice web UI which you can access on[http://localhost:8000/api/todo/](http://localhost:8000/api/todo/) using a browser.
80
92
81
93
To create a to-do item with cURL, you can just run this:
82
94
@@ -103,13 +115,13 @@ In return, you'll get your to-do item alongside the embedding of the `descriptio
103
115
104
116
The embedding contains 384 floating point numbers; we removed most of them in this blog post to make sure it fits on the page.
105
117
106
-
You can try creating multiple to-do items for fun and profit. If the description is changed, so will the embedding, demonstrating how the`intfloat/e5-small` modelis understanding the semantic meaning of your text.
118
+
You can try creating multiple to-do items for fun and profit. If the description is changed, so will the embedding, demonstrating how the`intfloat/e5-small` modelunderstands the semantic meaning of your text.
107
119
108
120
###Searching
109
121
110
122
Once you have a few embeddings and to-dos stored in your database, the fun part of searching can begin. In a typical search example with PostgreSQL, you'd now be using`tsvector` to keyword match your to-dos to the search query with term frequency. That's a good technique, but semantic search is better.
111
123
112
-
We've created a simplesearch endpointthataccepts a query, a completed to-do filter, and a limit. To use it, you can justdo this:
124
+
Oursearch endpoint accepts a query, a completed to-do filter, and a limit. To use it, you can justrun this:
113
125
114
126
```bash
115
127
curl \
@@ -122,7 +134,7 @@ curl \
122
134
If you've created a bunch of different to-do items, you should get only one search result back, and exactly the one you were expecting:
123
135
124
136
```json
125
-
"Make a New Year resolution list"
137
+
"Make a New Year resolution"
126
138
```
127
139
128
140
You can increase the`limit` to something larger and you should get more documents, in decreasing order of relevance.