Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle context window #51

Closed
wants to merge 9 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
Loading