Skip to content

Commit

Permalink
Initial rag (#52)
Browse files Browse the repository at this point in the history
* update signature

* optionally trim context

* handle context limits

* bump tomls

* cleanup debug

* update api name

* change to rag

* update test name

* try dropping

* update ci

* re-create ext w/ each test

* fix format
  • Loading branch information
ChuckHend authored Feb 14, 2024
1 parent 52a2c4c commit a2e6da1
Show file tree
Hide file tree
Showing 12 changed files with 279 additions and 49 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/extension_ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ jobs:
with:
working-directory: ./
- name: Cargo format
run: cargo +nightly fmt --all --check
run: cargo fmt --all --check
- name: Clippy
run: cargo clippy

Expand Down Expand Up @@ -123,13 +123,13 @@ jobs:
rm -rf ./target/pgrx-test-data-* || true
- name: unit-test
run: |
cargo pgrx test
make test-unit
- name: integration-test
run: |
pgrx15_config=$(/usr/local/bin/stoml ~/.pgrx/config.toml configs.pg15)
pg_version=$(/usr/local/bin/stoml Cargo.toml features.default)
echo "\q" | make run
cargo test -- --ignored --test-threads=1
make test-integration
publish:
if: github.event_name == 'release'
Expand Down
6 changes: 3 additions & 3 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "vectorize"
version = "0.9.0"
version = "0.10.0"
edition = "2021"
publish = false

Expand Down
7 changes: 7 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,10 @@ pgxn-zip: $(DISTNAME)-$(DISTVERSION).zip

clean:
@rm -rf META.json $(DISTNAME)-$(DISTVERSION).zip


test-integration:
cargo test -- --ignored --test-threads=1

test-unit:
cargo pgrx test
2 changes: 1 addition & 1 deletion Trunk.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ description = "The simplest way to orchestrate vector search on Postgres."
homepage = "https://github.com/tembo-io/pg_vectorize"
documentation = "https://github.com/tembo-io/pg_vectorize"
categories = ["orchestration", "machine_learning"]
version = "0.9.0"
version = "0.10.0"

[build]
postgres_version = "15"
Expand Down
22 changes: 19 additions & 3 deletions src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ fn transform_embeddings(

#[allow(clippy::too_many_arguments)]
#[pg_extern]
fn chat_table(
fn init_rag(
agent_name: &str,
table_name: &str,
unique_record_id: &str,
Expand Down Expand Up @@ -121,14 +121,30 @@ fn chat_table(

/// creates an table indexed with embeddings for chat completion workloads
#[pg_extern]
fn chat(
fn rag(
agent_name: &str,
query: &str,
// chat models: currently only supports gpt 3.5 and 4
// https://platform.openai.com/docs/models/gpt-3-5-turbo
// https://platform.openai.com/docs/models/gpt-4-and-gpt-4-turbo
chat_model: default!(&str, "'gpt-3.5-turbo'"),
// points to the type of prompt template to use
task: default!(&str, "'question_answer'"),
api_key: default!(Option<&str>, "NULL"),
// number of records to include in the context
num_context: default!(i32, 2),
// truncates context to fit the model's context window
force_trim: default!(bool, false),
) -> Result<TableIterator<'static, (name!(chat_results, pgrx::JsonB),)>> {
let resp = call_chat(agent_name, query, chat_model, task, api_key)?;
let resp = call_chat(
agent_name,
query,
chat_model,
task,
api_key,
num_context,
force_trim,
)?;
let iter = vec![(pgrx::JsonB(serde_json::to_value(resp)?),)];
Ok(TableIterator::new(iter))
}
Loading

0 comments on commit a2e6da1

Please sign in to comment.