pg.ddx.io  pgvector/pgvector GitHub issues and pull requests  
help / color / mirror / Atom feed
From: rmincling (@rmincling) <noreply+rmincling@github.com>
To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>
Subject: [pgvector/pgvector] issue #675: Question Setting ef_search to different values does not affect number of results retrieved (Django 4.2 + PGVector + HNSW index)
Date: Mon, 16 Sep 2024 14:08:25 +0000
Message-ID: <gh-pgvector-pgvector-675@github.com> (raw)

Hi all,

I have this simple Django model setup:

```
class AiVector(models.Model):
    # Embeddings
    embedding_sbert = VectorField(dimensions=768, null=True, blank=True) # using SBERT embedding (all-mpnet-base-v2)

    class Meta:
        indexes = [
            # SBERT
            HnswIndex(
                name='vector_sbert_index',
                fields=['embedding_sbert'],
                m=16,
                ef_construction=64, 
                opclasses=['vector_cosine_ops']  
            )]
```

I am trying to do a basic vector search (cosine) on the model with a simple question/embedding with the following code:
```
         with connection.cursor() as cursor:
                cursor.execute("SET LOCAL hnsw.ef_search = 40")
            self.matching_vectors = AiVector.objects \
                .annotate(distance=CosineDistance("embedding_sbert", text_query_embedding)) \
                .filter(distance__lte=0.8)
```
No matter what i set ef_search to, whether it be 1, 40, 60, 100, I always get the same number of results. What is the correct way to set ef_search?

Regards,

Rob


view thread (12+ messages)  latest in thread

Message-ID: <gh-pgvector-pgvector-675@github.com>
Permalink:  ../gh-pgvector-pgvector-675@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