Skip to content

Commit c0426b3

Browse files
ChuckHendAdam Hendel
and
Adam Hendel
authored
doc update (#105)
* add doc for self-hosted models * docs * diff model * update model * update sig on docs * update formatting * update table * add docs ci * path * update compose * add path * fix install cmd * add token * only main --------- Co-authored-by: Adam Hendel <[email protected]>
1 parent b9fa75b commit c0426b3

File tree

13 files changed

+352
-69
lines changed

13 files changed

+352
-69
lines changed

.github/workflows/docs.yml

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
name: Docs CI Workflow
2+
on:
3+
push:
4+
branches:
5+
- main
6+
paths:
7+
- 'docs/**'
8+
- '.github/workflows/docs.yml'
9+
jobs:
10+
deploy:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v4
14+
- uses: actions/setup-python@v2
15+
with:
16+
python-version: 3.11
17+
- run: curl -sSL https://install.python-poetry.org | POETRY_VERSION=1.7.1 python3 -
18+
- run: poetry install
19+
20+
- name: deploy docs
21+
env:
22+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
23+
run: poetry run mkdocs gh-deploy --force

Makefile

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
.PHONY: docs
2+
3+
docs:
4+
poetry install --no-directory --no-root
5+
poetry run mkdocs serve

README.md

+30-9
Original file line numberDiff line numberDiff line change
@@ -125,12 +125,12 @@ Create a job to vectorize the products table. We'll specify the tables primary k
125125

126126
```sql
127127
SELECT vectorize.table(
128-
job_name => 'product_search_hf',
129-
"table" => 'products',
128+
job_name => 'product_search_hf',
129+
"table" => 'products',
130130
primary_key => 'product_id',
131-
columns => ARRAY['product_name', 'description'],
131+
columns => ARRAY['product_name', 'description'],
132132
transformer => 'sentence-transformers/multi-qa-MiniLM-L6-dot-v1',
133-
schedule => 'realtime'
133+
schedule => 'realtime'
134134
);
135135
```
136136

@@ -140,10 +140,10 @@ Then search,
140140

141141
```sql
142142
SELECT * FROM vectorize.search(
143-
job_name => 'product_search_hf',
144-
query => 'accessories for mobile devices',
145-
return_columns => ARRAY['product_id', 'product_name'],
146-
num_results => 3
143+
job_name => 'product_search_hf',
144+
query => 'accessories for mobile devices',
145+
return_columns => ARRAY['product_id', 'product_name'],
146+
num_results => 3
147147
);
148148
```
149149

@@ -184,6 +184,9 @@ ALTER TABLE products
184184
ADD COLUMN context TEXT GENERATED ALWAYS AS (product_name || ': ' || description) STORED;
185185
```
186186

187+
Initialize the RAG project.
188+
We'll use the `sentence-transformers/all-MiniLM-L12-v2` model to generate embeddings on our source documents.
189+
187190
```sql
188191
SELECT vectorize.init_rag(
189192
agent_name => 'product_chat',
@@ -194,17 +197,35 @@ SELECT vectorize.init_rag(
194197
);
195198
```
196199

200+
Now we can ask questions of the `products` table and get responses from the `product_chat` agent using the `openai/gpt-3.5-turbo` generative model.
201+
197202
```sql
198203
SELECT vectorize.rag(
199204
agent_name => 'product_chat',
200-
query => 'What is a pencil?'
205+
query => 'What is a pencil?',
206+
chat_model => 'openai/gpt-3.5-turbo'
201207
) -> 'chat_response';
202208
```
203209

204210
```text
205211
"A pencil is an item that is commonly used for writing and is known to be most effective on paper."
206212
```
207213

214+
And to use a locally hosted Ollama service, change the `chat_model` parameter:
215+
216+
```sql
217+
SELECT vectorize.rag(
218+
agent_name => 'product_chat',
219+
query => 'What is a pencil?',
220+
chat_model => 'ollama/wizardlm2:7b'
221+
) -> 'chat_response';
222+
```
223+
224+
```text
225+
" A pencil is a writing instrument that consists of a solid or gelignola wood core, known as the \"lead,\" encased in a cylindrical piece of breakable material (traditionally wood or plastic), which serves as the body of the pencil. The tip of the body is tapered to a point for writing, and it can mark paper with the imprint of the lead. When used on a sheet of paper, the combination of the pencil's lead and the paper creates a visible mark that is distinct from unmarked areas of the paper. Pencils are particularly well-suited for writing on paper, as they allow for precise control over the marks made."
226+
```
227+
228+
208229
:bulb: Note that the `-> 'chat_response'` addition selects for that field of the JSON object output. Removing it will show the full JSON object, including information on which documents were included in the contextual prompt.
209230

210231
## Updating Embeddings

docker-compose.yml

+8
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,11 @@ services:
1717
- 3001:3001
1818
environment:
1919
- OLLAMA_HOST=0.0.0.0:3001
20+
# deploy:
21+
# replicas: 1
22+
# resources:
23+
# reservations:
24+
# devices:
25+
# - driver: nvidia
26+
# count: 1
27+
# capabilities: [gpu]

docs/api/index.md

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
# PG Vectorize API Overview
22

33
pg vectorize provides tools for two closely related tasks; vector search and retrieval augmented generation (RAG), and there are APIs dedicated to both of these tasks. Vector search is an important component of RAG and the RAG APIs depend on the vector search APIs. It could be helpful to think of the vector search APIs as lower level than RAG. However, relative to Postgres's APIs, both of these vectorize APIs are very high level.
4-

docs/api/rag.md

+17-17
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ vectorize.init_rag(
1515
"unique_record_id" TEXT,
1616
"column" TEXT,
1717
"schema" TEXT DEFAULT 'public',
18-
"transformer" TEXT DEFAULT 'text-embedding-ada-002',
19-
"search_alg" vectorize.SimilarityAlg DEFAULT 'pgv_cosine_similarity',
18+
"transformer" TEXT DEFAULT 'openai/text-embedding-ada-002',
19+
"index_dist_type" vectorize.IndexDist DEFAULT 'pgv_hnsw_cosine',
2020
"table_method" vectorize.TableMethod DEFAULT 'append'
2121
) RETURNS TEXT
2222
```
@@ -31,18 +31,18 @@ vectorize.init_rag(
3131
| column | text | The name of the column that contains the content that is used for context for RAG. |
3232
| schema | text | The name of the schema where the table is located. Defaults to 'public'. |
3333
| transformer | text | The name of the transformer to use for the embeddings. Defaults to 'text-embedding-ada-002'. |
34-
| search_alg | SimilarityAlg | The name of the search algorithm to use. Defaults to 'pgv_cosine_similarity'. |
34+
| index_dist_type | IndexDist | The name of index type to build. Defaults to 'pgv_hnsw_cosine'. |
3535
| table_method | TableMethod | The method to use for the table. Defaults to 'append', which adds a column to the existing table. |
3636

3737
Example:
3838

3939
```sql
4040
select vectorize.init_rag(
41-
agent_name => 'tembo_chat',
42-
table_name => 'tembo_docs',
43-
unique_record_id => 'document_name',
44-
"column" => 'content',
45-
transformer => 'sentence-transformers/all-MiniLM-L12-v2'
41+
agent_name => 'tembo_chat',
42+
table_name => 'tembo_docs',
43+
unique_record_id => 'document_name',
44+
"column" => 'content',
45+
transformer => 'sentence-transformers/all-MiniLM-L12-v2'
4646
);
4747
```
4848

@@ -56,7 +56,7 @@ select vectorize.init_rag(
5656
vectorize."rag"(
5757
"agent_name" TEXT,
5858
"query" TEXT,
59-
"chat_model" TEXT DEFAULT 'gpt-3.5-turbo',
59+
"chat_model" TEXT DEFAULT 'openai/gpt-3.5-turbo',
6060
"task" TEXT DEFAULT 'question_answer',
6161
"api_key" TEXT DEFAULT NULL,
6262
"num_context" INT DEFAULT 2,
@@ -81,10 +81,10 @@ vectorize."rag"(
8181

8282
```sql
8383
select vectorize.rag(
84-
agent_name => 'tembo_support',
85-
query => 'what are the major features from the tembo kubernetes operator?',
86-
chat_model => 'gpt-3.5-turbo',
87-
force_trim => 'true'
84+
agent_name => 'tembo_support',
85+
query => 'what are the major features from the tembo kubernetes operator?',
86+
chat_model => 'openai/gpt-3.5-turbo',
87+
force_trim => 'true'
8888
);
8989
```
9090

@@ -112,10 +112,10 @@ Filter the results to just the `chat_response`:
112112

113113
```sql
114114
select vectorize.rag(
115-
agent_name => 'tembo_support',
116-
query => 'what are the major features from the tembo kubernetes operator?',
117-
chat_model => 'gpt-3.5-turbo',
118-
force_trim => 'true'
115+
agent_name => 'tembo_support',
116+
query => 'what are the major features from the tembo kubernetes operator?',
117+
chat_model => 'gpt-3.5-turbo',
118+
force_trim => 'true'
119119
) -> 'chat_response';
120120
```
121121

docs/api/search.md

+16-16
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ vectorize."table"(
1515
"args" json DEFAULT '{}',
1616
"schema" TEXT DEFAULT 'public',
1717
"update_col" TEXT DEFAULT 'last_updated_at',
18-
"transformer" TEXT DEFAULT 'text-embedding-ada-002',
19-
"search_alg" vectorize.SimilarityAlg DEFAULT 'pgv_cosine_similarity',
18+
"transformer" TEXT DEFAULT 'openai/text-embedding-ada-002',
19+
"index_dist_type" vectorize.IndexDist DEFAULT 'pgv_hnsw_cosine',
2020
"table_method" vectorize.TableMethod DEFAULT 'join',
2121
"schedule" TEXT DEFAULT '* * * * *'
2222
) RETURNS TEXT
@@ -32,7 +32,7 @@ vectorize."table"(
3232
| schema | text | The name of the schema where the table is located. Defaults to 'public'. |
3333
| update_col | text | Column specifying the last time the record was updated. Required for cron-like schedule. Defaults to `last_updated_at` |
3434
| transformer | text | The name of the transformer to use for the embeddings. Defaults to 'text-embedding-ada-002'. |
35-
| search_alg | SimilarityAlg | The name of the search algorithm to use. Defaults to 'pgv_cosine_similarity'. |
35+
| index_dist_type | IndexDist | The name of index type to build. Defaults to 'pgv_hnsw_cosine'. |
3636
| table_method | TableMethod | `join` to store embeddings in a new table in the vectorize schema. `append` to create columns for embeddings on the source table. Defaults to `join`. |
3737
| schedule | text | Accepts a cron-like input for a cron based updates. Or `realtime` to set up a trigger. |
3838

@@ -47,12 +47,12 @@ Pass the API key into the function call via `args`.
4747

4848
```sql
4949
select vectorize.table(
50-
job_name => 'product_search',
51-
"table" => 'products',
50+
job_name => 'product_search',
51+
"table" => 'products',
5252
primary_key => 'product_id',
53-
columns => ARRAY['product_name', 'description'],
54-
transformer => 'text-embedding-ada-002',
55-
args => '{"api_key": "my-openai-key"}'
53+
columns => ARRAY['product_name', 'description'],
54+
transformer => 'openai/text-embedding-ada-002',
55+
args => '{"api_key": "my-openai-key"}'
5656
);
5757
```
5858

@@ -67,11 +67,11 @@ Then call `vectorize.table()` without providing the API key.
6767

6868
```sql
6969
select vectorize.table(
70-
job_name => 'product_search',
71-
"table" => 'products',
70+
job_name => 'product_search',
71+
"table" => 'products',
7272
primary_key => 'product_id',
73-
columns => ARRAY['product_name', 'description'],
74-
transformer => 'text-embedding-ada-002'
73+
columns => ARRAY['product_name', 'description'],
74+
transformer => 'openai/text-embedding-ada-002'
7575
);
7676
```
7777

@@ -106,10 +106,10 @@ vectorize."search"(
106106

107107
```sql
108108
SELECT * FROM vectorize.search(
109-
job_name => 'product_search',
110-
query => 'mobile electronic devices',
111-
return_columns => ARRAY['product_id', 'product_name'],
112-
num_results => 3
109+
job_name => 'product_search',
110+
query => 'mobile electronic devices',
111+
return_columns => ARRAY['product_id', 'product_name'],
112+
num_results => 3
113113
);
114114
```
115115

docs/api/utilities.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44

55
Transforms a block of text to embeddings using the specified transformer.
66

7-
Requires the `vector-serve` container to be set via `vectorize.embedding_svc_url`, or an OpenAI key to be set if using OpenAI embedding models.
7+
Requires the `vector-serve` container to be set via `vectorize.embedding_service_url`, or an OpenAI key to be set if using OpenAI embedding models.
88

99
```sql
1010
vectorize."transform_embeddings"(
1111
"input" TEXT,
12-
"model_name" TEXT DEFAULT 'text-embedding-ada-002',
12+
"model_name" TEXT DEFAULT 'openai/text-embedding-ada-002',
1313
"api_key" TEXT DEFAULT NULL
1414
) RETURNS double precision[]
1515
```
@@ -26,8 +26,8 @@ vectorize."transform_embeddings"(
2626

2727
```sql
2828
select vectorize.transform_embeddings(
29-
input => 'the quick brown fox jumped over the lazy dogs',
30-
model_name => 'sentence-transformers/multi-qa-MiniLM-L6-dot-v1'
29+
input => 'the quick brown fox jumped over the lazy dogs',
30+
model_name => 'sentence-transformers/multi-qa-MiniLM-L6-dot-v1'
3131
);
3232

3333
{-0.2556323707103729,-0.3213586211204529 ..., -0.0951206386089325}
@@ -37,7 +37,7 @@ select vectorize.transform_embeddings(
3737

3838
Configure `vectorize` to run on a database other than the default `postgres`.
3939

40-
Note that when making this change, it's also required to update `pg_cron` such that its corresponding background workers also connect to the appropriate database.
40+
Note that when making this change, it's also required to update `pg_cron` such that its corresponding background workers also connect to the appropriate database.
4141

4242
### Example
4343

docs/examples/openai_embeddings.md

+8-8
Original file line numberDiff line numberDiff line change
@@ -22,22 +22,22 @@ Then create the job.
2222

2323
```sql
2424
SELECT vectorize.table(
25-
job_name => 'product_search_openai',
26-
"table" => 'products',
25+
job_name => 'product_search_openai',
26+
"table" => 'products',
2727
primary_key => 'product_id',
28-
columns => ARRAY['product_name', 'description'],
29-
transformer => 'text-embedding-ada-002'
28+
columns => ARRAY['product_name', 'description'],
29+
transformer => 'openai/text-embedding-ada-002'
3030
);
3131
```
3232

3333
To search the table, use the `vectorize.search` function.
3434

3535
```sql
3636
SELECT * FROM vectorize.search(
37-
job_name => 'product_search_openai',
38-
query => 'accessories for mobile devices',
39-
return_columns => ARRAY['product_id', 'product_name'],
40-
num_results => 3
37+
job_name => 'product_search_openai',
38+
query => 'accessories for mobile devices',
39+
return_columns => ARRAY['product_id', 'product_name'],
40+
num_results => 3
4141
);
4242
```
4343

docs/examples/sentence_transformers.md

+8-8
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,12 @@ Create a job to vectorize the products table. We'll specify the tables primary k
5353

5454
```sql
5555
SELECT vectorize.table(
56-
job_name => 'product_search_hf',
57-
"table" => 'products',
56+
job_name => 'product_search_hf',
57+
"table" => 'products',
5858
primary_key => 'product_id',
59-
columns => ARRAY['product_name', 'description'],
59+
columns => ARRAY['product_name', 'description'],
6060
transformer => 'sentence-transformers/multi-qa-MiniLM-L6-dot-v1',
61-
scheduler => 'realtime'
61+
scheduler => 'realtime'
6262
);
6363
```
6464

@@ -68,10 +68,10 @@ Then search,
6868

6969
```sql
7070
SELECT * FROM vectorize.search(
71-
job_name => 'product_search_hf',
72-
query => 'accessories for mobile devices',
73-
return_columns => ARRAY['product_id', 'product_name'],
74-
num_results => 3
71+
job_name => 'product_search_hf',
72+
query => 'accessories for mobile devices',
73+
return_columns => ARRAY['product_id', 'product_name'],
74+
num_results => 3
7575
);
7676

7777
search_results

0 commit comments

Comments
 (0)