Skip to content

Commit

Permalink
Making the .load(ctx) call only once shaves off ~50 seconds on the AN…
Browse files Browse the repository at this point in the history
…N Benchmarks Kosarak dataset (#35)
  • Loading branch information
alexklibisz committed Feb 14, 2020
1 parent de009de commit 3c2d25c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,14 @@ class KnnExactScoreFunction(val similarity: Similarity,
import KnnExactScoreFunction.vectorCache

override def getLeafScoreFunction(ctx: LeafReaderContext): LeafScoreFunction = {
// This .load call is expensive so it's important to only instantiate once.
lazy val atomicFieldData = fieldData.load(ctx)

new LeafScoreFunction {
override def score(docId: Int, subQueryScore: Float): Double = {
lazy val storedVector = if (useCache) {
vectorCache.get((ctx, docId), () => fieldData.load(ctx).getElastiKnnVector(docId).get)
} else fieldData.load(ctx).getElastiKnnVector(docId).get
vectorCache.get((ctx, docId), () => atomicFieldData.getElastiKnnVector(docId).get)
} else atomicFieldData.getElastiKnnVector(docId).get
val (sim, _) = ExactSimilarity(similarity, queryVector, storedVector).get
sim
}
Expand Down
2 changes: 1 addition & 1 deletion version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.1.0-PRE4
0.1.0-PRE5

0 comments on commit 3c2d25c

Please sign in to comment.