objectbox-java
objectbox-java copied to clipboard
Vector is missing for neighbor to repair
Is there an existing issue?
- [x] I have searched existing issues
Build info
- ObjectBox version: 4.2.0
- OS: Android 15
- Device/ABI/architecture: Pixel 6 Pro
Steps to reproduce
- Save data with vector
@HnswIndex(dimensions = 2, distanceType = VectorDistanceType.GEO) - Save at least a couple of thousand of them
- 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)
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 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 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.
@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?
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.