Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit68bb388

Browse files
authored
SQL api docs (#1426)
1 parent65b898d commit68bb388

File tree

4 files changed

+175
-47
lines changed

4 files changed

+175
-47
lines changed

‎pgml-cms/docs/SUMMARY.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
##API
1616

1717
*[Overview](api/apis.md)
18-
*[SQLExtension](api/sql-extension/README.md)
18+
*[SQLextension](api/sql-extension/README.md)
1919
*[pgml.deploy()](api/sql-extension/pgml.deploy.md)
2020
*[pgml.embed()](api/sql-extension/pgml.embed.md)
2121
*[pgml.chunk()](api/sql-extension/pgml.chunk.md)
@@ -85,7 +85,7 @@
8585
*[Documents](resources/data-storage-and-retrieval/documents.md)
8686
*[Partitioning](resources/data-storage-and-retrieval/partitioning.md)
8787
*[LLM based pipelines with PostgresML and dbt (data build tool)](resources/data-storage-and-retrieval/llm-based-pipelines-with-postgresml-and-dbt-data-build-tool.md)
88-
*[Benchmarks](resources/benchmarks/README.md)
88+
*[Benchmarks](resources/benchmarks/postgresml-is-8-40x-faster-than-python-http-microservices.md)
8989
*[PostgresML is 8-40x faster than Python HTTP microservices](resources/benchmarks/postgresml-is-8-40x-faster-than-python-http-microservices.md)
9090
*[Scaling to 1 Million Requests per Second](resources/benchmarks/million-requests-per-second.md)
9191
*[MindsDB vs PostgresML](resources/benchmarks/mindsdb-vs-postgresml.md)

‎pgml-cms/docs/api/apis.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,11 @@ The PostgreSQL extension provides all of the ML & AI functionality, like trainin
1818

1919
The following functions are implemented and maintained by the PostgresML extension:
2020

21-
| Functionname| Description|
21+
| Function| Description|
2222
|------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
2323
|[pgml.embed()](sql-extension/pgml.embed)| Generate embeddings inside the database using open source embedding models from Hugging Face.|
2424
|[pgml.transform()](sql-extension/pgml.transform/)| Download and run latest Hugging Face transformer models, like Llama, Mixtral, and many more to perform various NLP tasks like text generation, summarization, sentiment analysis and more.|
25+
| pgml.transform_stream()| Streaming version of[pgml.transform()](sql-extension/pgml.transform/). Retrieve tokens as they are generated by the LLM, decreasing time to first token.|
2526
|[pgml.train()](sql-extension/pgml.train/)| Train a machine learning model on data from a Postgres table or view. Supports XGBoost, LightGBM, Catboost and all Scikit-learn algorithms.|
2627
|[pgml.deploy()](sql-extension/pgml.deploy)| Deploy a version of the model created with pgml.train().|
2728
|[pgml.predict()](sql-extension/pgml.predict/)| Perform real time inference using a model trained with pgml.train() on live application data.|
@@ -33,7 +34,7 @@ Together with standard database functionality provided by PostgreSQL, these func
3334

3435
The client SDK implements best practices and common use cases, using the PostgresML SQL functions and standard PostgreSQL features to do it. The SDK core is written in Rust, which manages creating and running queries, connection pooling, and error handling.
3536

36-
For each additional language we support (current JavaScript and Python), we create and publish language-native bindings. This architecture ensures all programming languages we support have identical APIs and similar performance when interacting with PostgresML.
37+
For each additional language we support (currently JavaScript and Python), we create and publish language-native bindings. This architecture ensures all programming languages we support have identical APIs and similar performance when interacting with PostgresML.
3738

3839
###Use cases
3940

Lines changed: 169 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,69 +1,196 @@
11
---
22
description:>-
3-
Thepgml extension for PostgreSQL provides Machine Learning and Artificial
3+
ThePostgresML extension for PostgreSQL provides Machine Learning and Artificial
44
Intelligence APIs with access to algorithms to train your models, or download
5-
SOTA open source models fromHuggingFace.
5+
state-of-the-art open source models fromHugging Face.
66
---
77

8-
#SQLExtension
8+
#SQLextension
99

10-
##Open Source Models
10+
PostgresML is a PostgreSQL extension which adds SQL functions to the database. Those functions provide access to AI models downloaded from Hugging Face, and classical machine learning algorithms like XGBoost and LightGBM.
1111

12-
PostgresML integrates[🤗 Hugging Face Transformers](https://huggingface.co/transformers)tobring state-of-the-art models intothedata layer. There are tens of thousands of pre-trainedmodelswith pipelines to turn raw inputs into useful results. Many LLMs have been publishedandmade available for download. You will wanttobrowse all the[models](https://huggingface.co/models) available to find the perfect solution for your[dataset](https://huggingface.co/dataset)and[task](https://huggingface.co/tasks). The pgml extension provides a few APIs for different use cases:
12+
Our SQL API is stable and safetouse in your applications, whilethe models andalgorithms we support continuetoevolveandimprove.
1313

14-
*[pgml.embed.md](pgml.embed.md"mention") returns vector embeddings for nearest neighbor searches and other vector database use cases
15-
*[pgml.generate.md](pgml.generate.md"mention") returns streaming text responses for chatbots
16-
*[pgml.transform](../../api/sql-extension/pgml.transform/"mention") allows you to perform dozens of natural language processing (NLP) tasks with thousands of models, like sentiment analysis, question and answering, translation, summarization and text generation
17-
*[pgml.tune.md](pgml.tune.md"mention") fine tunes an open source model on your own data
14+
##Open-source LLMs
1815

19-
##Train & deploy your ownmodels
16+
PostgresML defines two SQL functions which use[🤗 Hugging Face](https://huggingface.co/transformers) transformers and embeddingsmodels, running directly in the database:
2017

21-
PostgresML also supports more than 50 machine learning algorithms to train your own models for classification, regression or clustering. We organize a family of Models in Projects that are intended to address a particular opportunity. Different algorithms can be used in the same Project, to test and compare the performance of various approaches, and track progress over time, all within your database.
18+
| Function| Description|
19+
|---------------|-------------|
20+
|[pgml.embed()](pgml.embed)| Generate embeddings using latest sentence transformers from Hugging Face.|
21+
|[pgml.transform()](pgml.transform/)| Text generation using LLMs like Llama, Mixtral, and many more, with models downloaded from Hugging Face.|
22+
| pgml.transform_stream()| Streaming version of[pgml.transform()](pgml.transform/), which fetches partial responses as they are being generated by the model, substantially decreasing time to first token.|
23+
|[pgml.tune()](pgml.tune)| Perform fine tuning tasks on Hugging Face models, using data stored in the database.|
2224

23-
###Train
25+
###Example
2426

25-
Training creates a Model based on the data in your database.
27+
Using a SQL function for interacting with open-source models makes things really easy:
2628

27-
```sql
28-
SELECTpgml.train(
29-
project_name=>'Sales Forecast',
30-
task=>'regression',
31-
relation_name=>'hist_sales',
32-
y_column_name=>'next_sales',
33-
algorithm=>'xgboost'
34-
);
29+
{% tabs %}
30+
{% tab title="SQL" %}
31+
32+
```postgresql
33+
SELECT pgml.embed(
34+
'intfloat/e5-small',
35+
'This text will be embedded using the intfloat/e5-small model.'
36+
) AS embedding;
37+
```
38+
39+
{% endtab %}
40+
{% tab title="Output" %}
41+
42+
```
43+
embedding
44+
-------------------------------------------
45+
{-0.028478337,-0.06275077,-0.04322059, [...]
3546
```
3647

37-
See[pgml.train](../../api/sql-extension/pgml.train/README.md) for more information.
48+
{% endtab %}
49+
{% endtabs %}
50+
51+
Using the`pgml` SQL functions inside regular queries, it's possible to add embeddings and LLM-generated text inside any query, without the data ever leaving the database, removing the cost of a remote network call.
52+
53+
##Classical machine learning
54+
55+
PostgresML defines four SQL functions which allow training regression, classification, and clustering models on tabular data:
56+
57+
| Function| Description|
58+
|---------------|-------------|
59+
|[pgml.train()](pgml.train/)| Train a model on PostgreSQL tables or views using any algorithm from Scikit-learn, with the additional support for XGBoost, LightGBM and Catboost.|
60+
|[pgml.predict()](pgml.predict/)| Run inference on live application data using a model trained with[pgml.train()](pgml.train/).|
61+
|[pgml.deploy()](pgml.deploy)| Deploy a specific version of a model trained with pgml.train(), using your own accuracy metrics.|
62+
| pgml.load_dataset()| Load any of the toy datasets from Scikit-learn or any dataset from Hugging Face.|
63+
64+
###Example
65+
66+
####Load data
3867

39-
###Deploy
68+
Using`pgml.load_dataset()`, we can load an example classification dataset from Scikit-learn:
4069

41-
Deploy an active Model for a particular Project, using a deployment strategy to select the best model.
70+
{% tabs %}
71+
{% tab title="SQL" %}
4272

43-
```sql
44-
SELECTpgml.deploy(
45-
project_name=>'Sales Forecast',
46-
strategy=>'best_score',
47-
algorithm=>'xgboost'
73+
```postgresql
74+
SELECT *
75+
FROM pgml.load_dataset('digits');
76+
```
77+
78+
{% endtab %}
79+
{% tab title="Output" %}
80+
81+
```
82+
table_name | rows
83+
-------------+------
84+
pgml.digits | 1797
85+
(1 row)
86+
```
87+
88+
{% endtab %}
89+
{% endtabs %}
90+
91+
####Train a model
92+
93+
Once we have some data, we can train a model on this data using[pgml.train()](pgml.train/):
94+
95+
{% tabs %}
96+
{% tab title="SQL" %}
97+
98+
```postgresql
99+
SELECT *
100+
FROM pgml.train(
101+
project_name => 'My project name',
102+
task => 'classification',
103+
relation_name =>'pgml.digits',
104+
y_column_name => 'target',
105+
algorithm => 'xgboost',
48106
);
49107
```
50108

51-
See[pgml.deploy.md](pgml.deploy.md"mention") for more information.
109+
{% endtab %}
110+
{% tab title="Output" %}
52111

53-
###Predict
112+
```
113+
INFO: Metrics: {
114+
"f1": 0.8755124,
115+
"precision": 0.87670505,
116+
"recall": 0.88005465,
117+
"accuracy": 0.87750554,
118+
"mcc": 0.8645154,
119+
"fit_time": 0.33504912,
120+
"score_time": 0.001842427
121+
}
122+
123+
project | task | algorithm | deployed
124+
-----------------+----------------+-----------+----------
125+
My project name | classification | xgboost | t
126+
(1 row)
54127
55-
Use your Model on novel data points not seen during training to infer a new data point.
128+
```
129+
130+
{% endtab %}
131+
{% endtabs %}
132+
133+
[pgml.train()](pgml.train/) reads data from the table, using the`target` column as the label, automatically splits the dataset into test and train sets, and trains an XGBoost model. Our extension supports more than 50 machine learning algorithms, and you can train a model using any of them by just changing the name of the`algorithm` argument.
134+
135+
136+
####Real time inference
137+
138+
Now that we have a model, we can use it to predict new data points, in real time, on live application data:
56139

57-
```sql
58-
SELECTpgml.predict(
59-
project_name=>'Sales Forecast',
60-
features=> ARRAY[
61-
last_week_sales,
62-
week_of_year
63-
]
140+
{% tabs %}
141+
{% tab title="SQL" %}
142+
143+
```postgresql
144+
SELECT
145+
target,
146+
pgml.predict(
147+
'My project name',
148+
image
64149
) AS prediction
65-
FROM new_sales
66-
ORDER BY predictionDESC;
150+
FROM
151+
pgml.digits
152+
LIMIT 1;
153+
```
154+
155+
{% endtab %}
156+
{% tab title="Output" %}
157+
158+
```
159+
target | prediction
160+
--------+------------
161+
0 | 0
162+
(1 row)
163+
```
164+
165+
{% endtab %}
166+
{% endtabs %}
167+
168+
####Change model version
169+
170+
The train function automatically deploys the best model into production, using the precision score relevant to the type of the model. If you prefer to deploy models using your own accuracy metrics, the[pgml.deploy()](pgml.deploy) function can manually change which model version is used for subsequent database queries:
171+
172+
{% tabs %}
173+
{% tab title="SQL" %}
174+
175+
```postgresql
176+
SELECT *
177+
FROM
178+
pgml.deploy(
179+
'My project name',
180+
strategy => 'most_recent',
181+
algorithm => 'xgboost'
182+
);
183+
```
184+
185+
{% endtab %}
186+
{% tab title="Output" %}
187+
188+
```
189+
project | strategy | algorithm
190+
-----------------+-------------+-----------
191+
My project name | most_recent | xgboost
192+
(1 row)
67193
```
68194

69-
See[pgml.predict](../../api/sql-extension/pgml.predict/"mention") for more information.
195+
{% endtab %}
196+
{% endtabs %}

‎pgml-dashboard/src/components/cms/index_link/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ impl IndexLink {
7373
self
7474
}
7575

76-
// Adds a suffix to this and all children ids.
76+
// Adds a suffix to this and all children ids.
7777
// this prevents id collision with multiple naves on one screen
7878
// like d-none for mobile nav
7979
pubfnid_suffix(mutself,id_suffix:&str) ->IndexLink{

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp