henomis / lingoose

🪿 LinGoose is a Go framework for building awesome AI/LLM applications.
https://lingoose.io
MIT License
660 stars 56 forks source link

Error when using Postgres Index #218

Closed ollyw closed 3 weeks ago

ollyw commented 1 month ago

Describe the bug The pgvector index creates malformed queries.

To Reproduce Steps to reproduce the behavior:

  1. Run postgresql with pgvector
  2. execute https://github.com/henomis/lingoose/blob/main/examples/embeddings/postgres/main.go
  3. A panic happens in the test with the error "internal index error: pq: syntax error at or near \"<=>\""

Expected behavior The query works and outputs the purpose of Nato (as per the question)

Potential fix It looks like the query parameters are swapped round. Simply changing them causes it to start working. In order to check it works with a non-empy filter also, the query was modified like so:

    similarities, err := index.Query(
        context.Background(),
        query,
        indexoption.WithTopK(3),
        indexoption.WithFilter("where metadata->>'source' = 'state_of_the_union.txt'"),
    )

This executed fine. Then updating the row with Nato in to be a difference source caused the down to be excluded, as expected