-
-
Notifications
You must be signed in to change notification settings - Fork 653
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
vectorstores: add pgvector #377
Conversation
fe102bc
to
10f3b4d
Compare
if _, err = tx.Exec(ctx, "SELECT pg_advisory_xact_lock(1573678846307946494)"); err != nil { | ||
return err | ||
} | ||
sql := fmt.Sprintf(`CREATE TABLE IF NOT EXISTS %s ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rather than string-assemble this can you use arguments to Exec (throughout) -- this protects against sql injection attacks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMO, according to https://www.postgresql.org/docs/current/xfunc-sql.html#XFUNC-SQL-FUNCTION-ARGUMENTS: SQL function arguments can only be used as data values, not as identifiers.
replacing the table name with $1 does not seem to work.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think Travis maybe means that you shouldn't Sprintf
into package sql
calls like Exec
, but rather use the args
of each method, e.g. look at the example at https://pkg.go.dev/database/sql#example-Conn.ExecContext
result, err := conn.ExecContext(ctx,
UPDATE balances SET balance = balance + 10 WHERE user_id = ?;, id)
See how id
is passed into the SQL query?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes that's what I meant.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I may be getting it, but it seems difficult to do this if we wants to keep the table name as a parameter create table ?
or create table $1
will both report an error, and I have to use the Sprint
function and do Sanitize()
when the user passes in the table name.
Or, we can fix the table name to be a constant and unchangeable.
Everywhere else, $1
is used to replace the parameter.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add/include an example showing usage. |
279e046
to
18c19d2
Compare
Should I refer to the |
if _, err = tx.Exec(ctx, "SELECT pg_advisory_xact_lock(1573678846307946494)"); err != nil { | ||
return err | ||
} | ||
sql := fmt.Sprintf(`CREATE TABLE IF NOT EXISTS %s ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think Travis maybe means that you shouldn't Sprintf
into package sql
calls like Exec
, but rather use the args
of each method, e.g. look at the example at https://pkg.go.dev/database/sql#example-Conn.ExecContext
result, err := conn.ExecContext(ctx,
UPDATE balances SET balance = balance + 10 WHERE user_id = ?;, id)
See how id
is passed into the SQL query?
d9641b0
to
f6493ae
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think my review comments have been addressed
On to @tmc to approve and merge if he's happy with the PR
Signed-off-by: Abirdcfly <fp544037857@gmail.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
That would work, I'd love to see more ollama examples but you can you openai, up to you. |
PR Checklist
memory: add interfaces for X, Y
orutil: add whizzbang helpers
).Fixes #123
).golangci-lint
checks.