pg.ddx.io  pgvector/pgvector GitHub issues and pull requests  
help / color / mirror / Atom feed
From: vincenzon (@vincenzon) <noreply+vincenzon@github.com>
To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>
Subject: [pgvector/pgvector] issue #263: No results when using index
Date: Tue, 12 Sep 2023 19:08:29 +0000
Message-ID: <gh-pgvector-pgvector-263@github.com> (raw)

I have a table of quotes with vector embeddings. There are two columns in the table, one is indexed one is not, they are otherwise identical. When I query against the unindexed column for the 5 nearest neighbors to a given embedding, I get 5 results. However, when I run the same query using the indexed column I get no results. 

```
conn = psycopg2.connect(connectionStr)
register_vector(conn)

embedding = model.encode(["I can't do that"])

with conn.cursor() as cur:
    t0 = time.time()
    cur.execute("""
        select movie_line
        from quotes
        where  character = 'hal'
            and movie_line like '%%Dave%%'
        order by (embedding <=> %s)
        limit 1
        """, embedding)
    
    rows = cur.fetchall()
    t1 = time.time()
    
    print(f"Time: {t1 - t0}s")
    
    for r in rows:
        print(r)
conn.close()
```

Produces: 

```
Time: 4.286221981048584s
("I'm sorry, Dave, but in accordance with sub-routine C1532/4, quote, When the crew are dead or incapacitated, the computer must assume control, unquote. I must, therefore, override your authority now since you are not in any condition to intel- ligently exercise it.",)
```

But changing to use the indexed column, embedding2, in the order by clause, and setting the probes parameter

```
cur.execute("set ivfflat.probes = 28;")
...
order by (embedding2 <=> %s)
...
```

Returns no results. 

How can using an index in an order by clause lead to no results being returned? 

This is entirely reproducible, so if there is any debugging I can do to help diagnose the issue, let me know.

view thread (17+ messages)  latest in thread

Message-ID: <gh-pgvector-pgvector-263@github.com>
Permalink:  ../gh-pgvector-pgvector-263@github.com/

 · 


This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox