typesense / typesense/typesense

Nearest neighbor k value changes results

Open
#1,225 2 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C++
Stars
26.6k
Forks
973
Avg merge
18h 45m
Merged PRs (30d)
4

Description

Description

I'm noticing some weird behavior when adjusting the k value (and per_page) from 10 to 15 with my dataset. I was expecting it to simply add 5 new items, but it's adding 4 to the tail and inserting one near the head. Shouldn't increasing k value never do this or am I misunderstanding?

image

def find_nearest(search_embeddings, vec_field=''):
    requests = {
        'searches': [
            {
                'collection': 'games',
                'q': '*',
                'per_page': 10,
                'vector_query': f'{vec_field}vec:({json.dumps(search_embeddings)}, k:10)'
            }
        ]
    }
    response = ts.client.multi_search.perform(requests, {})['results'][0]
    # print_game each game name in response
    for item in response['hits']:
        print(item['document']['name'])

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the reported behavior with the Python find_nearest example, comparing vector_query k and per_page values against the games collection. Trace the nearest-neighbor search entry point and existing vector-search tests, if present, to determine whether changing k should preserve ordering; done means the behavior is corrected or its semantics are clearly documented.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp, python
Domain
search
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.