Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Semantic Router
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
mirrored_repos
MachineLearning
aurelio-labs
Semantic Router
Commits
703ff79e
Commit
703ff79e
authored
9 months ago
by
Lawson Taylor
Browse files
Options
Downloads
Patches
Plain Diff
[DOCS] add docker image for postgres
parent
889a7360
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
compose.yaml
+0
-20
0 additions, 20 deletions
compose.yaml
docs/indexes/postgres/postgres.compose.yaml
+0
-0
0 additions, 0 deletions
docs/indexes/postgres/postgres.compose.yaml
docs/indexes/postgres/postgres.ipynb
+33
-6
33 additions, 6 deletions
docs/indexes/postgres/postgres.ipynb
with
33 additions
and
26 deletions
compose.yaml
deleted
100644 → 0
+
0
−
20
View file @
889a7360
services
:
postgres
:
container_name
:
pgvector
image
:
ankane/pgvector
restart
:
always
shm_size
:
128mb
ports
:
-
"
5432:5432"
environment
:
POSTGRES_USER
:
user
POSTGRES_PASSWORD
:
password
POSTGRES_DB
:
semantic_router
volumes
:
-
postgres_data:/var/lib/pgvector/data
volumes
:
postgres_data
:
driver
:
local
\ No newline at end of file
This diff is collapsed.
Click to expand it.
docs/indexes/postgres/postgres.compose.yaml
0 → 100644
+
0
−
0
View file @
703ff79e
This diff is collapsed.
Click to expand it.
docs/indexes/postgres.ipynb
→
docs/indexes/postgres
/postgres
.ipynb
+
33
−
6
View file @
703ff79e
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Postgres pgvector index example\n",
"\n",
"**Note**: You'll require docker to be installed locally, or a remote instance of Postgres with the pgvector extension installed."
]
},
{
"cell_type": "code",
"execution_count":
null
,
"execution_count":
11
,
"metadata": {},
"outputs": [],
"source": []
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"/Users/frankjames/Projects/semantic-router/docs/indexes/postgres\n",
"\u001b[1A\u001b[1B\u001b[0G\u001b[?25l[+] Running 0/0\n",
" \u001b[33m⠋\u001b[0m Container pgvector Starting \u001b[34m0.1s \u001b[0m\n",
"\u001b[?25h\u001b[1A\u001b[1A\u001b[0G\u001b[?25l\u001b[34m[+] Running 1/1\u001b[0m\n",
" \u001b[32m✔\u001b[0m Container pgvector \u001b[32mStarted\u001b[0m \u001b[34m0.1s \u001b[0m\n",
"\u001b[?25h"
]
}
],
"source": [
"!echo \"Running docker compose to start postgres instance with pgvector extension\"\n",
"!docker compose -f ./postgres.compose.yaml up --detach"
]
},
{
"cell_type": "code",
...
...
@@ -67,11 +92,13 @@
"metadata": {},
"outputs": [],
"source": [
"from semantic_router.index.postgres import PostgresIndex
\n",
"from semantic_router.index.postgres import PostgresIndex\n",
"import os\n",
"\n",
"os.environ[\"POSTGRES_CONNECTION_STRING\"] = \"postgresql://user:password@localhost:5432/semantic_router\"\n",
"postgres_index = PostgresIndex()\n"
"os.environ[\"POSTGRES_CONNECTION_STRING\"] = (\n",
" \"postgresql://user:password@localhost:5432/semantic_router\"\n",
")\n",
"postgres_index = PostgresIndex()"
]
},
{
...
...
%% Cell type:markdown id: tags:
# Postgres pgvector index example
**Note**
: You'll require docker to be installed locally, or a remote instance of Postgres with the pgvector extension installed.
%% Cell type:code id: tags:
```
python
!
echo
"
Running docker compose to start postgres instance with pgvector extension
"
!
docker
compose
-
f
.
/
postgres
.
compose
.
yaml
up
--
detach
```
%% Output
/Users/frankjames/Projects/semantic-router/docs/indexes/postgres
[1A[1B[0G[?25l[+] Running 0/0
[33m⠋[0m Container pgvector Starting [34m0.1s [0m
[?25h[1A[1A[0G[?25l[34m[+] Running 1/1[0m
[32m✔[0m Container pgvector [32mStarted[0m [34m0.1s [0m
[?25h
%% Cell type:code id: tags:
```
python
from
semantic_router
import
Route
# we could use this as a guide for our chatbot to avoid political conversations
politics
=
Route
(
name
=
"
politics
"
,
utterances
=
[
"
isn
'
t politics the best thing ever
"
,
"
why don
'
t you tell me about your political opinions
"
,
"
don
'
t you just love the president
"
"
don
'
t you just hate the president
"
,
"
they
'
re going to destroy this country!
"
,
"
they will save the country!
"
,
],
)
# this could be used as an indicator to our chatbot to switch to a more
# conversational prompt
chitchat
=
Route
(
name
=
"
chitchat
"
,
utterances
=
[
"
how
'
s the weather today?
"
,
"
how are things going?
"
,
"
lovely weather today
"
,
"
the weather is horrendous
"
,
"
let
'
s go to the chippy
"
,
],
)
# we place both of our decisions together into single list
routes
=
[
politics
,
chitchat
]
```
%% Cell type:code id: tags:
```
python
import
os
from
getpass
import
getpass
from
semantic_router.encoders
import
OpenAIEncoder
# get at platform.openai.com
os
.
environ
[
"
OPENAI_API_KEY
"
]
=
os
.
environ
.
get
(
"
OPENAI_API_KEY
"
)
or
getpass
(
"
Enter OpenAI API key:
"
)
encoder
=
OpenAIEncoder
()
```
%% Cell type:code id: tags:
```
python
from
semantic_router.index.postgres
import
PostgresIndex
import
os
os.environ["POSTGRES_CONNECTION_STRING"] = "postgresql://user:password@localhost:5432/semantic_router"
os
.
environ
[
"
POSTGRES_CONNECTION_STRING
"
]
=
(
"
postgresql://user:password@localhost:5432/semantic_router
"
)
postgres_index
=
PostgresIndex
()
```
%% Cell type:code id: tags:
```
python
from
semantic_router.layer
import
RouteLayer
rl
=
RouteLayer
(
encoder
=
encoder
,
routes
=
routes
,
index
=
postgres_index
)
```
%% Cell type:markdown id: tags:
We can check our route layer and index information.
%% Cell type:code id: tags:
```
python
rl
.
list_route_names
()
```
%% Cell type:code id: tags:
```
python
len
(
rl
.
index
)
```
%% Cell type:markdown id: tags:
We can also view all of the records for a given route:
%% Cell type:code id: tags:
```
python
rl
.
index
.
_get_route_ids
(
route_name
=
"
politics
"
)
```
%% Cell type:markdown id: tags:
And query:
%% Cell type:code id: tags:
```
python
rl
(
"
I like voting
"
)
```
%% Cell type:code id: tags:
```
python
rl
(
"
how
'
s the weather today?
"
).
name
```
%% Cell type:code id: tags:
```
python
rl
(
"
where are you?
"
).
name
```
%% Cell type:markdown id: tags:
We can delete or update routes.
%% Cell type:code id: tags:
```
python
len
(
rl
.
index
)
```
%% Cell type:code id: tags:
```
python
import
time
rl
.
delete
(
route_name
=
"
chitchat
"
)
time
.
sleep
(
1
)
len
(
rl
.
index
)
```
%% Cell type:code id: tags:
```
python
rl
(
"
how
'
s the weather today?
"
).
name
```
%% Cell type:code id: tags:
```
python
rl
.
index
.
get_routes
()
```
%% Cell type:code id: tags:
```
python
rl
.
index
.
describe
()
```
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment