Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions rust/lance-index/protos-cache/cache.proto
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ message CompressedPostingHeader {
// Number of documents in each compressed posting block. Older cache entries
// omit this field and decode as the legacy 128-doc block size.
uint32 block_size = 6;
// Whether an impact IPC section follows the posting/position sections.
bool has_impacts = 7;
}

// Header for a serialized `PlainPostingList` cache entry. Followed by an Arrow
Expand Down
1 change: 1 addition & 0 deletions rust/lance-index/src/scalar/inverted.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
pub mod builder;
mod cache_codec;
mod encoding;
mod impact;
mod index;
mod iter;
pub mod json;
Expand Down
49 changes: 47 additions & 2 deletions rust/lance-index/src/scalar/inverted/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1733,24 +1733,45 @@ pub fn inverted_list_schema_for_version_with_block_size(
with_position: bool,
format_version: InvertedListFormatVersion,
block_size: usize,
) -> SchemaRef {
inverted_list_schema_for_version_with_block_size_and_impacts(
with_position,
format_version,
block_size,
true,
)
}

pub(crate) fn inverted_list_schema_for_version_with_block_size_and_impacts(
with_position: bool,
format_version: InvertedListFormatVersion,
block_size: usize,
with_impacts: bool,
) -> SchemaRef {
validate_format_version_block_size(format_version, block_size)
.expect("invalid FTS format version for posting block size");
match format_version {
InvertedListFormatVersion::V1 => inverted_list_schema_v1(with_position, block_size),
InvertedListFormatVersion::V1 => {
inverted_list_schema_v1(with_position, block_size, with_impacts)
}
InvertedListFormatVersion::V2 | InvertedListFormatVersion::V3 => {
inverted_list_schema_with_tail_codec_and_position_codec(
with_position,
format_version,
PostingTailCodec::VarintDelta,
Some(PositionStreamCodec::PackedDelta),
block_size,
with_impacts,
)
}
}
}

fn inverted_list_schema_v1(with_position: bool, block_size: usize) -> SchemaRef {
fn inverted_list_schema_v1(
with_position: bool,
block_size: usize,
with_impacts: bool,
) -> SchemaRef {
let mut fields = vec![
arrow_schema::Field::new(
POSTING_COL,
Expand All @@ -1764,6 +1785,17 @@ fn inverted_list_schema_v1(with_position: bool, block_size: usize) -> SchemaRef
arrow_schema::Field::new(MAX_SCORE_COL, datatypes::DataType::Float32, false),
arrow_schema::Field::new(LENGTH_COL, datatypes::DataType::UInt32, false),
];
if with_impacts {
fields.push(arrow_schema::Field::new(
IMPACT_COL,
datatypes::DataType::List(Arc::new(Field::new(
"item",
datatypes::DataType::LargeBinary,
true,
))),
false,
));
}
if with_position {
fields.push(arrow_schema::Field::new(
POSITION_COL,
Expand Down Expand Up @@ -1806,6 +1838,7 @@ pub fn inverted_list_schema_with_tail_codec(
posting_tail_codec,
Some(PositionStreamCodec::PackedDelta),
LEGACY_BLOCK_SIZE,
false,
)
}

Expand All @@ -1815,6 +1848,7 @@ fn inverted_list_schema_with_tail_codec_and_position_codec(
posting_tail_codec: PostingTailCodec,
position_codec: Option<PositionStreamCodec>,
block_size: usize,
with_impacts: bool,
) -> SchemaRef {
let mut fields = vec![
// we compress the posting lists (including row ids and frequencies),
Expand All @@ -1831,6 +1865,17 @@ fn inverted_list_schema_with_tail_codec_and_position_codec(
arrow_schema::Field::new(MAX_SCORE_COL, datatypes::DataType::Float32, false),
arrow_schema::Field::new(LENGTH_COL, datatypes::DataType::UInt32, false),
];
if with_impacts {
fields.push(arrow_schema::Field::new(
IMPACT_COL,
datatypes::DataType::List(Arc::new(Field::new(
"item",
datatypes::DataType::LargeBinary,
true,
))),
false,
));
}
if with_position {
fields.push(arrow_schema::Field::new(
COMPRESSED_POSITION_COL,
Expand Down
Loading
Loading