Skip to content

Plugin QPS (Quantum Proximity Scoring)

QPS, short for Quantum Proximity Scoring, is a new algorithm developed for Orama that enhances document relevance by evaluating token proximity within a document.

QPS tokenizes the content into distinct segments, or “quantums,” and assigns importance to tokens based on their proximity within these quantums.

The scoring algorithm boosts documents with closely located matching tokens, calculating a relevance score based on token frequency, proximity, and bitwise operations to improve the accuracy and speed of search results.

Installation

You can install the plugin using any major Node.js package manager.

Terminal window
npm install @orama/plugin-qps

Usage

This plugin will replace the default scoring algorithm (BM25) with the Quantum Proximity Scoring algorithm, making search faster and the index size smaller.

import { create } from '@orama/orama'
import { pluginQPS } from '@orama/plugin-qps'
const db = create({
schema: {
title: 'string',
description: 'string',
rating: 'number',
},
plugins: [pluginQPS()],
})

And that’s it! The Orama plugin will do the rest for you.

QPS vs BM25, pros and cons

QPS and BM25 are two very different scoring algorithms, and they offer pros and cons depending on the use case.

QPS Pros

  • Proximity-Based Scoring: QPS places significant importance on how close tokens are to each other in a document, which enhances search relevance, especially for queries where context or proximity of terms is important (e.g., “machine learning” vs. “learning machine”).

  • Improved Relevance: By quantizing tokens and evaluating their positions within specific segments, QPS can prioritize documents with tightly related search terms, leading to more relevant search results.

  • Efficient for Short, Focused Queries: QPS can excel in scenarios where queries involve key terms that are contextually important in proximity, making it well-suited for short, specific searches.

  • High Accuracy for Exact and Fuzzy Matches: QPS can handle both exact and approximate matches by adjusting tolerance levels, allowing for fuzzy search capabilities while maintaining high accuracy in results.

  • Smaller index size: QPS doesn’t store term frequencies and other metadata, which results in a smaller index size compared to BM25. This also reflects on the memory usage and the speed of the search.

QPS Cons

  • Proximity May Not Always Be Relevant: In some cases, proximity between tokens may not significantly impact relevance (e.g., for long-form content or technical documentation). QPS might over-prioritize proximity when it’s not critical for certain types of searches.

  • Limited Effectiveness for Long Queries: QPS may not perform as well for longer queries where token proximity becomes less important or when there is a need to balance proximity with other relevance factors.

How to choose

We believe that for most applications, QPS will provide better search results than BM25. However, it’s essential to consider the nature of your content and the types of queries you expect to receive.

BM25, being a more traditional scoring algorithm, might be more suitable for long-form content or when proximity is not a critical factor in search relevance.

On the other hand, QPS can significantly enhance search results for short, focused queries, exact and fuzzy matches, and scenarios where token proximity is essential for relevance.

We reccommend trying both algorithms and measuring the results to determine which one works best for your use case.