objectbox-java icon indicating copy to clipboard operation
objectbox-java copied to clipboard

Vector is missing for neighbor to repair

Open poldz123 opened this issue 6 months ago • 3 comments
trafficstars

Is there an existing issue?

Build info

  • ObjectBox version: 4.2.0
  • OS: Android 15
  • Device/ABI/architecture: Pixel 6 Pro

Steps to reproduce

  1. Save data with vector @HnswIndex(dimensions = 2, distanceType = VectorDistanceType.GEO)
  2. Save at least a couple of thousand of them
  3. And delete all of them

Expected behavior

I should be able to remove all of them without exception.

Actual behavior

An exception is being thrown (see logs below), and the data still persists. There's currently no way to delete all of it via a query. I want to avoid clearing the entire database entity.

Code

sampleEntity.store.runInTx {
    val query = scheduleEntity.query(
        (SampleEntity_.sampleId equal operator.sampleId)
    ).build()
    query.remove()
    query.close()
}
Code
[Paste your code here]

Logs, stack traces

java.lang.IllegalStateException: Vector is missing for neighbor to repair 27900; level: 2, removed: 29219, neighbor's degree: 1
at io.objectbox.query.Query.nativeRemove(Native Method)
at io.objectbox.query.Query.lambda$remove$11$io-objectbox-query-Query(Query.java:918)
at io.objectbox.query.Query$$ExternalSyntheticLambda1.call(D8$$SyntheticClass:0)
at io.objectbox.Box.internalCallWithWriterHandle(Box.java:757)
at io.objectbox.query.Query.remove(Query.java:918)

poldz123 avatar May 20 '25 16:05 poldz123

Thanks for reporting. But please clarify: do you want to delete all of them one by one using the query you have given? Or really just one?

If you need to delete all at once, does using Box.removeAll() work?

Edit: this is unexpected, we should reproduce this and create an internal issue if needed.

greenrobot-team avatar May 26 '25 05:05 greenrobot-team

@greenrobot-team I have multiple data within the entity with a respective ID which I only want to remove. Box.removeAll() is not possible since it removes all of the data.

I want to remove all of the data within the entity based on the ID

poldz123 avatar May 29 '25 19:05 poldz123

@poldz123 Thanks for clarifying. I got confused because you wrote "delete all of them" multiple times.

As I said, this is not expected and we need to investigate this.

greenrobot-team avatar Jun 02 '25 06:06 greenrobot-team

@poldz123 I was trying to reproduce the issue on an Android 15 device and the same ObjectBox version. Here's the entity that I am using,

@Entity
class SampleEntity {
    @Id
    var id: Long = 0L

    var vectorId: Long = 0L

    @HnswIndex(dimensions = 2, distanceType = VectorDistanceType.GEO)
    var vector: FloatArray = floatArrayOf()
}

and the following instrumented test to reproduce the issue,

@RunWith(AndroidJUnit4::class)
class ExampleInstrumentedTest {
    private lateinit var box: Box<SampleEntity>

    @Before
    fun setup() {
        box = ObjectBoxStore.store.boxFor(SampleEntity::class.java)
    }

    @Test
    fun checkIfThrows() {
        // 10K entities inserted in a single transaction
        val entities =
            List<SampleEntity>(10_000, init = { idx ->
                val entity = SampleEntity()
                // 'vectorId' is not the ID property of SampleEntity
                entity.vectorId = idx + 1_000L
                entity.vector = FloatArray(2) { Random.nextFloat() }
                entity
            })
        box.put(entities)

        assertThrows(IllegalStateException::class.java) {
            // Execute a delete operation 20000 times
            // wherein for each operation a random entity is deleted
            repeat(20000) {
                val randomVectorId = Random.nextLong(1_000L, 11_000L)
                ObjectBoxStore.store.runInTx {
                    val query = box.query(SampleEntity_.vectorId.equal(randomVectorId)).build()
                    query.remove()
                    query.close()
                }
            }
        }
    }

    @After
    fun cleanup() {
        box.removeAll()
    }
}

Even after running this test multiple tests, no exception is thrown. Is there any detail that I should include in my code that would help me reproduce the issue?

shubham0204 avatar Aug 02 '25 14:08 shubham0204

Without additional information, we are unfortunately not sure how to resolve this issue. Therefore this issue has been automatically closed. Feel free to comment with additional details and we can re-open this issue.

github-actions[bot] avatar Aug 27 '25 01:08 github-actions[bot]