Skip to content

Commit

Permalink
Changes to float and assert distance rather than ids
Browse files Browse the repository at this point in the history
  • Loading branch information
net-cscience-raphael committed Aug 30, 2024
1 parent 8e61a76 commit 7c40489
Showing 1 changed file with 3 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -105,19 +105,16 @@ abstract class AbstractFloatVectorDescriptorReaderTest(schemaPath: String) : Abs
@ParameterizedTest
@EnumSource(mode = EnumSource.Mode.EXCLUDE, names = ["JACCARD", "HAMMING"])
fun testNearestNeighbourSearch(distance: Distance) {


val writer = this.testConnection.getDescriptorWriter(this.field)
val reader = this.testConnection.getDescriptorReader(this.field)
val random = SplittableRandom()

/* Generate and store test data. */
val descriptors = this.initialize(writer, random)


/* Perform nearest neighbour search. */
val query = ProximityQuery(
Value.DoubleVector(DoubleArray(3) { random.nextDouble() }),
Value.FloatVector(FloatArray(3) { random.nextFloat() }),
distance,
SortOrder.ASC,
100,
Expand All @@ -126,16 +123,10 @@ abstract class AbstractFloatVectorDescriptorReaderTest(schemaPath: String) : Abs
val result = reader.query(query).toList()

/* Make manual query and compare. */
val manual = descriptors.sortedBy { vec ->
distance(
Value.DoubleVector(DoubleArray(3) { i -> vec.vector.value[i].toDouble() }),
query.value
)
}.take(100)
val manual = descriptors.sortedBy { distance(it.vector, query.value) }.take(100)
result.zip(manual).forEach {
Assertions.assertEquals(it.first.id, it.second.id)
Assertions.assertEquals( distance(it.first.vector,query.value), distance(it.second.vector,query.value))
}

}

/**
Expand Down

0 comments on commit 7c40489

Please sign in to comment.