-
-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Verify quantized index after compression
Make the `--check` flag to take effect when compressing an index. Signed-off-by: Michal Siedlaczek <michal@siedlaczek.me>
- Loading branch information
Showing
5 changed files
with
169 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,45 @@ | ||
#pragma once | ||
|
||
#include <algorithm> | ||
#include <cmath> | ||
#include <cstdint> | ||
#include <utility> | ||
|
||
#include "index_scorer.hpp" | ||
#include "linear_quantizer.hpp" | ||
|
||
namespace pisa { | ||
|
||
template <typename Wand> | ||
struct quantized: public index_scorer<Wand> { | ||
using index_scorer<Wand>::index_scorer; | ||
|
||
term_scorer_t term_scorer([[maybe_unused]] uint64_t term_id) const { | ||
return []([[maybe_unused]] uint32_t doc, uint32_t freq) { return freq; }; | ||
} | ||
}; | ||
|
||
/** | ||
* Uses internal scorer and quantizer to produce quantized scores. | ||
* | ||
* This is not inheriting from `index_scorer` because it returns int scores. | ||
*/ | ||
template <typename Wand> | ||
class QuantizingScorer { | ||
private: | ||
std::unique_ptr<index_scorer<Wand>> m_scorer; | ||
LinearQuantizer m_quantizer; | ||
|
||
public: | ||
QuantizingScorer(std::unique_ptr<index_scorer<Wand>> scorer, LinearQuantizer quantizer) | ||
: m_scorer(std::move(scorer)), m_quantizer(quantizer) {} | ||
|
||
[[nodiscard]] auto term_scorer(std::uint64_t term_id) const | ||
-> std::function<std::uint32_t(std::uint32_t, std::uint32_t)> { | ||
return | ||
[this, scorer = m_scorer->term_scorer(term_id)](std::uint32_t doc, std::uint32_t freq) { | ||
return this->m_quantizer(scorer(doc, freq)); | ||
}; | ||
} | ||
}; | ||
|
||
} // namespace pisa |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
#define CATCH_CONFIG_MAIN | ||
#include "catch2/catch.hpp" | ||
|
||
#include "pisa/compress.hpp" | ||
#include "pisa/scorer/scorer.hpp" | ||
#include "pisa/wand_data.hpp" | ||
#include "pisa_config.hpp" | ||
#include "temporary_directory.hpp" | ||
#include "type_safe.hpp" | ||
#include "wand_utils.hpp" | ||
|
||
TEST_CASE("Compress block index", "[index][compress]") { | ||
std::string encoding = GENERATE( | ||
"ef", | ||
"single", | ||
"pefuniform", | ||
"pefopt", | ||
"block_optpfor", | ||
"block_varintg8iu", | ||
"block_streamvbyte", | ||
"block_maskedvbyte", | ||
"block_varintgb", | ||
"block_interpolative", | ||
"block_qmx", | ||
"block_simple8b", | ||
"block_simple16", | ||
"block_simdbp" | ||
); | ||
pisa::TemporaryDirectory tmp; | ||
pisa::compress( | ||
PISA_SOURCE_DIR "/test/test_data/test_collection", | ||
std::nullopt, // no wand | ||
encoding, | ||
(tmp.path() / encoding).string(), | ||
ScorerParams(""), // no scorer | ||
std::nullopt, // no quantization | ||
true // check=true | ||
); | ||
} | ||
|
||
TEST_CASE("Compress quantized block index", "[index][compress]") { | ||
auto input = PISA_SOURCE_DIR "/test/test_data/test_collection"; | ||
|
||
std::string scorer = GENERATE("bm25"); | ||
CAPTURE(scorer); | ||
auto scorer_params = ScorerParams(scorer); | ||
|
||
pisa::TemporaryDirectory tmp; | ||
pisa::create_wand_data( | ||
(tmp.path() / "wand").string(), | ||
input, | ||
pisa::FixedBlock(64), | ||
scorer_params, | ||
false, | ||
false, | ||
pisa::Size(8), | ||
std::unordered_set<std::size_t>() | ||
); | ||
|
||
std::string encoding = GENERATE( | ||
"ef", | ||
"single", | ||
"pefuniform", | ||
"pefopt", | ||
"block_optpfor", | ||
"block_varintg8iu", | ||
"block_streamvbyte", | ||
"block_maskedvbyte", | ||
"block_varintgb", | ||
"block_interpolative", | ||
"block_qmx", | ||
"block_simple8b", | ||
"block_simple16", | ||
"block_simdbp" | ||
); | ||
CAPTURE(encoding); | ||
|
||
pisa::compress( | ||
input, | ||
(tmp.path() / "wand").string(), | ||
encoding, | ||
(tmp.path() / encoding).string(), | ||
scorer_params, | ||
pisa::Size(8), | ||
true // check=true | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters