Skip to content

Commit

Permalink
Minimal rag framework (#49)
Browse files Browse the repository at this point in the history
* add chat interface module

* add test
  • Loading branch information
ChuckHend authored Feb 12, 2024
1 parent 151f124 commit 52a2c4c
Show file tree
Hide file tree
Showing 13 changed files with 707 additions and 206 deletions.
155 changes: 148 additions & 7 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@ pg_test = []
[dependencies]
anyhow = "1.0.72"
chrono = {version = "0.4.26", features = ["serde"] }
handlebars = "5.1.0"
lazy_static = "1.4.0"
log = "0.4.19"
openai-api-rs = "4.0.6"
pgmq = "0.26.1"
pgrx = "0.11.3"
postgres-types = "0.2.5"
Expand Down
4 changes: 2 additions & 2 deletions META.json.in
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "vectorize",
"abstract": "The simplest way to do vector search on Postgres",
"description": "Vectorize automates that the transformation and orchestration of text to embeddings, allowing you to do vector and semantic search on existing data with as little as two function calls.",
"description": "Vectorize automates the transformation and orchestration of text to embeddings, allowing you to do vector and semantic search on existing data with as little as two function calls.",
"version": "@CARGO_VERSION@",
"maintainer": [
"Tembo <admin+pgxn@tembo.io>"
Expand All @@ -20,7 +20,7 @@
"requires": {
"PostgreSQL": "11.0.0",
"pg_cron": "1.5.0",
"pgmq": "0.30.0",
"pgmq": "1.1.0",
"pgvector": "1.5.0"
}
}
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ sqlx-cache:
cargo sqlx prepare

format:
SQLX_OFFLINE=${SQLX_OFFLINE} cargo +nightly fmt --all
SQLX_OFFLINE=${SQLX_OFFLINE} cargo fmt --all
SQLX_OFFLINE=${SQLX_OFFLINE} cargo clippy

# ensure the DATABASE_URL is not used, since pgrx will stop postgres during compile
Expand Down
15 changes: 15 additions & 0 deletions sql/meta.sql
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,18 @@ CREATE TABLE vectorize.job (
params jsonb NOT NULL,
last_completion TIMESTAMP WITH TIME ZONE
);

CREATE TABLE vectorize.prompts (
prompt_type TEXT NOT NULL UNIQUE,
sys_prompt TEXT NOT NULL,
user_prompt TEXT NOT NULL
);

INSERT INTO vectorize.prompts (prompt_type, sys_prompt, user_prompt)
VALUES (
'question_answer',
'You are an expert Q&A system.\nYou must always answer the question using the provided context information. Never use any prior knowledge.\nAdditional rules to follow:\n1. Never directly reference the given context in your answer.\n2. Never use responses like ''Based on the context, ...'' or ''The context information ...'' or any responses similar to that.',
'Context information is below.\n---------------------\n{{ context_str }}\n---------------------\nGiven the context information and not prior knowledge, answer the query.\n Query: {{ query_str }}\nAnswer: '
)
ON CONFLICT (prompt_type)
DO NOTHING;
14 changes: 14 additions & 0 deletions sql/vectorize--0.9.0--0.10.0.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
CREATE TABLE vectorize.prompts (
prompt_type TEXT NOT NULL UNIQUE,
sys_prompt TEXT NOT NULL,
user_prompt TEXT NOT NULL
);

INSERT INTO vectorize.prompts (prompt_type, sys_prompt, user_prompt)
VALUES (
'question_answer',
'You are an expert Q&A system.\nYou must always answer the question using the provided context information. Never use any prior knowledge.\nAdditional rules to follow:\n1. Never directly reference the given context in your answer.\n2. Never use responses like ''Based on the context, ...'' or ''The context information ...'' or any responses similar to that.',
'Context information is below.\n---------------------\n{{ context_str }}\n---------------------\nGiven the context information and not prior knowledge, answer the query.\n Query: {{ query_str }}\nAnswer: '
)
ON CONFLICT (prompt_type)
DO NOTHING;
Loading

0 comments on commit 52a2c4c

Please sign in to comment.