Skip to content

Commit df39965

Browse files
committed
dev: addressing code review
1 parent 1b26912 commit df39965

File tree

3 files changed

+9
-13
lines changed

3 files changed

+9
-13
lines changed

rig-postgres/README.md

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@
66
</picture>
77
<span style="font-size: 48px; margin: 0 20px; font-weight: regular; font-family: Open Sans, sans-serif;"> + </span>
88
<picture>
9-
<source media="(prefers-color-scheme: dark)" srcset="https://www.postgresql.org/media/img/about/press/elephant.png">
10-
<source media="(prefers-color-scheme: light)" srcset="https://www.postgresql.org/media/img/about/press/elephant.png">
9+
<source srcset="https://www.postgresql.org/media/img/about/press/elephant.png">
1110
<img src="https://www.postgresql.org/media/img/about/press/elephant.png" width="200" alt="SQLite logo">
1211
</picture>
1312
</div>
@@ -30,8 +29,8 @@ rig-postgres = "0.1.0"
3029

3130
You can also run `cargo add rig-core rig-postgres` to add the most recent versions of the dependencies to your project.
3231

33-
See the [`/examples`](./examples) folder for usage examples.
32+
## PostgreSQL usage
3433

35-
## Important Note
34+
The crate utilizes the [pgvector](https://github.com/pgvector/pgvector) extension, which is available for PostgreSQL version 13 and later. Use any of the [official](https://www.postgresql.org/download/) or alternative methods to install psql. The `pgvector` extension will be automatically installed by the crate if it's not present yet.
3635

37-
The crate utilizes the [pgvector](https://github.com/pgvector/pgvector) PostgreSQL extension. It will automatically install it in your database if it's not yet present.
36+
The crate relies on [`tokio-postgres`](https://docs.rs/tokio-postgres/latest/tokio_postgres/index.html) to manage its communication with the database. You can connect to a DB using any of the [supported methods](https://www.postgresql.org/docs/current/libpq-connect.html#LIBPQ-CONNSTRING). See the [`/examples`](./examples) folder for usage examples.

rig-postgres/examples/vector_search_postgres.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,6 @@ impl PostgresVectorStoreTable for Document {
3737

3838
#[tokio::main]
3939
async fn main() -> Result<(), anyhow::Error> {
40-
// tracing_subscriber::fmt().with_env_filter(
41-
// tracing_subscriber::EnvFilter::from_default_env()
42-
// .add_directive(tracing::Level::DEBUG.into())
43-
// .add_directive("hyper=off".parse().unwrap())
44-
// ).init();
45-
4640
// set up postgres connection
4741
let database_url = std::env::var("DATABASE_URL").expect("DATABASE_URL not set");
4842
let db_config: tokio_postgres::Config = database_url.parse()?;

rig-postgres/src/lib.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,11 @@ impl<E: EmbeddingModel + 'static, T: PostgresVectorStoreTable + 'static> Postgre
149149
.collect::<Vec<_>>()
150150
.into();
151151

152-
let values = doc.column_values();
153-
let params: Vec<&(dyn ToSql + Sync)> = values
152+
// building the parameters we use in the query:
153+
// first, we select only the values from the column_values() tuples
154+
// and then append the embedding vector as the last parameter for the insert query
155+
let column_values = doc.column_values();
156+
let params: Vec<&(dyn ToSql + Sync)> = column_values
154157
.iter()
155158
.map(|(_, v)| &**v)
156159
.chain(std::iter::once(&embedding_vector as &(dyn ToSql + Sync)))

0 commit comments

Comments
 (0)