[BUG] Knn Search Fails When Repeatedly Deleting and Inserting Vectors

Describe the bug
When performing Knn search queries on an index multiple times, with documents being deleted and inserted, the search occasionally does not return any hits.

To Reproduce

  1. Create a Knn index.
  2. Generate a vector to be used during tests.
  3. Add a document with the vector and refresh the index.
  4. Search for that vector and retrieve the document ID.
  5. Delete the document with the retrieved ID.
  6. Repeat steps 3-5 until the search returns no hits.

Expected behavior
The search query should consistently return hits as long as there are documents in the index.

Host/Environment (please complete the following information):

  • Operating System: M1 Mac (Also occurred on Linux/ARM64)
  • OpenSearch Version: 2.7.0/2.9.0

Additional context
Python script that reproduces issue is located in github issue: