Compare commits

...

14 Commits

Author SHA1 Message Date
YoEight
328718ee90 improve documentation 2025-12-11 16:30:04 -05:00
YoEight
a2878efafe time for some tests 2025-12-11 16:11:22 -05:00
YoEight
f392e0a0f8 threading down on_missing_document param 2025-12-11 15:54:11 -05:00
YoEight
e359325dbd rename to a clearer name 2025-12-11 14:31:16 -05:00
YoEight
d5f66c195d introduce DocumentCreationPolicy 2025-12-11 14:13:11 -05:00
YoEight
9f64b0de66 Allow strict document update without creating missing documents 2025-12-11 12:49:34 -05:00
Clément Renault
26e368b116 Merge pull request #6041 from meilisearch/fix-workflow-injection
Remove risk of command injection
2025-12-09 17:04:58 +00:00
curquiza
ba95ac0915 Remove risk of command injection 2025-12-09 17:06:41 +01:00
Clément Renault
75fcbfc2fe Merge pull request #6039 from meilisearch/bump-rust-to-1-19-1
Move to Rust v1.91.1
2025-12-09 13:55:08 +00:00
Kerollmops
8c19b6d55e Make the new Clippy happy 2025-12-09 14:33:04 +01:00
Kerollmops
08d0f05ece Remove a warning 2025-12-09 13:58:37 +01:00
Kerollmops
4762e9afa0 Move to Rust v1.91.1 2025-12-09 13:52:46 +01:00
Clément Renault
12fcab91c5 Merge pull request #6037 from meilisearch/fix-intel-mac
Fix macos-amd64 compilation
2025-12-08 13:21:51 +00:00
Louis Dureuil
792a72a23f Add missing cfg 2025-12-08 13:22:01 +01:00
54 changed files with 277 additions and 244 deletions

View File

@@ -18,7 +18,7 @@ jobs:
timeout-minutes: 180 # 3h
steps:
- uses: actions/checkout@v5
- uses: dtolnay/rust-toolchain@1.89
- uses: dtolnay/rust-toolchain@1.91.1
with:
profile: minimal

View File

@@ -66,7 +66,7 @@ jobs:
fetch-depth: 0 # fetch full history to be able to get main commit sha
ref: ${{ steps.comment-branch.outputs.head_ref }}
- uses: dtolnay/rust-toolchain@1.89
- uses: dtolnay/rust-toolchain@1.91.1
- name: Run benchmarks on PR ${{ github.event.issue.id }}
run: |

View File

@@ -12,7 +12,7 @@ jobs:
timeout-minutes: 180 # 3h
steps:
- uses: actions/checkout@v5
- uses: dtolnay/rust-toolchain@1.89
- uses: dtolnay/rust-toolchain@1.91.1
# Run benchmarks
- name: Run benchmarks - Dataset ${BENCH_NAME} - Branch main - Commit ${{ github.sha }}

View File

@@ -18,7 +18,7 @@ jobs:
timeout-minutes: 4320 # 72h
steps:
- uses: actions/checkout@v5
- uses: dtolnay/rust-toolchain@1.89
- uses: dtolnay/rust-toolchain@1.91.1
with:
profile: minimal

View File

@@ -44,7 +44,7 @@ jobs:
exit 1
fi
- uses: dtolnay/rust-toolchain@1.89
- uses: dtolnay/rust-toolchain@1.91.1
with:
profile: minimal

View File

@@ -16,7 +16,7 @@ jobs:
timeout-minutes: 4320 # 72h
steps:
- uses: actions/checkout@v5
- uses: dtolnay/rust-toolchain@1.89
- uses: dtolnay/rust-toolchain@1.91.1
with:
profile: minimal

View File

@@ -15,7 +15,7 @@ jobs:
runs-on: benchmarks
steps:
- uses: actions/checkout@v5
- uses: dtolnay/rust-toolchain@1.89
- uses: dtolnay/rust-toolchain@1.91.1
with:
profile: minimal

View File

@@ -15,7 +15,7 @@ jobs:
runs-on: benchmarks
steps:
- uses: actions/checkout@v5
- uses: dtolnay/rust-toolchain@1.89
- uses: dtolnay/rust-toolchain@1.91.1
with:
profile: minimal

View File

@@ -15,7 +15,7 @@ jobs:
runs-on: benchmarks
steps:
- uses: actions/checkout@v5
- uses: dtolnay/rust-toolchain@1.89
- uses: dtolnay/rust-toolchain@1.91.1
with:
profile: minimal

View File

@@ -3,7 +3,7 @@ name: Look for flaky tests
on:
workflow_dispatch:
schedule:
- cron: '0 4 * * *' # Every day at 4:00AM
- cron: "0 4 * * *" # Every day at 4:00AM
jobs:
flaky:
@@ -23,7 +23,7 @@ jobs:
run: |
apt-get update && apt-get install -y curl
apt-get install build-essential -y
- uses: dtolnay/rust-toolchain@1.89
- uses: dtolnay/rust-toolchain@1.91.1
- name: Install cargo-flaky
run: cargo install cargo-flaky
- name: Run cargo flaky in the dumps

View File

@@ -12,7 +12,7 @@ jobs:
timeout-minutes: 4320 # 72h
steps:
- uses: actions/checkout@v5
- uses: dtolnay/rust-toolchain@1.89
- uses: dtolnay/rust-toolchain@1.91.1
# Run benchmarks
- name: Run the fuzzer

View File

@@ -31,7 +31,7 @@ jobs:
sudo rm -rf "/usr/share/dotnet" || true
sudo rm -rf "/usr/local/lib/android" || true
sudo rm -rf "/usr/local/share/boost" || true
- uses: dtolnay/rust-toolchain@1.89
- uses: dtolnay/rust-toolchain@1.91.1
- name: Install cargo-deb
run: cargo install cargo-deb
- uses: actions/checkout@v5

View File

@@ -76,7 +76,7 @@ jobs:
needs: check-version
steps:
- uses: actions/checkout@v5
- uses: dtolnay/rust-toolchain@1.89
- uses: dtolnay/rust-toolchain@1.91.1
- name: Build
run: cargo build --release --locked ${{ matrix.feature-flag }} ${{ matrix.extra-args }}
# No need to upload binaries for dry run (cron or workflow_dispatch)

View File

@@ -25,14 +25,18 @@ jobs:
- uses: actions/checkout@v5
- name: Define the Docker image we need to use
id: define-image
env:
EVENT_NAME: ${{ github.event_name }}
DOCKER_IMAGE_INPUT: ${{ github.event.inputs.docker_image }}
run: |
event=${{ github.event_name }}
echo "docker-image=nightly" >> $GITHUB_OUTPUT
if [[ $event == 'workflow_dispatch' ]]; then
echo "docker-image=${{ github.event.inputs.docker_image }}" >> $GITHUB_OUTPUT
if [[ "$EVENT_NAME" == 'workflow_dispatch' ]]; then
echo "docker-image=$DOCKER_IMAGE_INPUT" >> $GITHUB_OUTPUT
fi
- name: Docker image is ${{ steps.define-image.outputs.docker-image }}
run: echo "Docker image is ${{ steps.define-image.outputs.docker-image }}"
env:
DOCKER_IMAGE: ${{ steps.define-image.outputs.docker-image }}
run: echo "Docker image is $DOCKER_IMAGE"
##########
## SDKs ##

View File

@@ -34,7 +34,7 @@ jobs:
- name: check free space after
run: df -h
- name: Setup test with Rust stable
uses: dtolnay/rust-toolchain@1.89
uses: dtolnay/rust-toolchain@1.91.1
- name: Cache dependencies
uses: Swatinem/rust-cache@v2.8.0
with:
@@ -63,7 +63,7 @@ jobs:
- uses: actions/checkout@v5
- name: Cache dependencies
uses: Swatinem/rust-cache@v2.8.0
- uses: dtolnay/rust-toolchain@1.89
- uses: dtolnay/rust-toolchain@1.91.1
- name: Run cargo build without any default features
uses: actions-rs/cargo@v1
with:
@@ -87,7 +87,7 @@ jobs:
sudo rm -rf "/usr/share/dotnet" || true
sudo rm -rf "/usr/local/lib/android" || true
sudo rm -rf "/usr/local/share/boost" || true
- uses: dtolnay/rust-toolchain@1.89
- uses: dtolnay/rust-toolchain@1.91.1
- name: Run cargo build with almost all features
run: |
cargo build --workspace --locked --features "$(cargo xtask list-features --exclude-feature cuda,test-ollama)"
@@ -145,7 +145,7 @@ jobs:
sudo rm -rf "/usr/share/dotnet" || true
sudo rm -rf "/usr/local/lib/android" || true
sudo rm -rf "/usr/local/share/boost" || true
- uses: dtolnay/rust-toolchain@1.89
- uses: dtolnay/rust-toolchain@1.91.1
- name: Run cargo tree without default features and check lindera is not present
run: |
if cargo tree -f '{p} {f}' -e normal --no-default-features | grep -qz lindera; then
@@ -167,7 +167,7 @@ jobs:
sudo rm -rf "/usr/share/dotnet" || true
sudo rm -rf "/usr/local/lib/android" || true
sudo rm -rf "/usr/local/share/boost" || true
- uses: dtolnay/rust-toolchain@1.89
- uses: dtolnay/rust-toolchain@1.91.1
- name: Cache dependencies
uses: Swatinem/rust-cache@v2.8.0
- name: Build
@@ -187,7 +187,7 @@ jobs:
sudo rm -rf "/usr/share/dotnet" || true
sudo rm -rf "/usr/local/lib/android" || true
sudo rm -rf "/usr/local/share/boost" || true
- uses: dtolnay/rust-toolchain@1.89
- uses: dtolnay/rust-toolchain@1.91.1
with:
components: clippy
- name: Cache dependencies
@@ -209,7 +209,7 @@ jobs:
sudo rm -rf "/usr/share/dotnet" || true
sudo rm -rf "/usr/local/lib/android" || true
sudo rm -rf "/usr/local/share/boost" || true
- uses: dtolnay/rust-toolchain@1.89
- uses: dtolnay/rust-toolchain@1.91.1
with:
components: rustfmt
- name: Cache dependencies
@@ -235,7 +235,7 @@ jobs:
sudo rm -rf "/usr/share/dotnet" || true
sudo rm -rf "/usr/local/lib/android" || true
sudo rm -rf "/usr/local/share/boost" || true
- uses: dtolnay/rust-toolchain@1.89
- uses: dtolnay/rust-toolchain@1.91.1
- name: Cache dependencies
uses: Swatinem/rust-cache@v2.8.0
- name: Run declarative tests

View File

@@ -24,7 +24,7 @@ jobs:
sudo rm -rf "/usr/share/dotnet" || true
sudo rm -rf "/usr/local/lib/android" || true
sudo rm -rf "/usr/local/share/boost" || true
- uses: dtolnay/rust-toolchain@1.89
- uses: dtolnay/rust-toolchain@1.91.1
- name: Install sd
run: cargo install sd
- name: Update Cargo.toml file

View File

@@ -107,19 +107,14 @@ impl Settings<Unchecked> {
}
}
#[derive(Debug, Clone, PartialEq)]
#[derive(Default, Debug, Clone, PartialEq)]
pub enum Setting<T> {
Set(T),
Reset,
#[default]
NotSet,
}
impl<T> Default for Setting<T> {
fn default() -> Self {
Self::NotSet
}
}
impl<T> Setting<T> {
pub const fn is_not_set(&self) -> bool {
matches!(self, Self::NotSet)

View File

@@ -161,19 +161,14 @@ pub struct Facets {
pub min_level_size: Option<NonZeroUsize>,
}
#[derive(Debug, Clone, PartialEq, Eq)]
#[derive(Default, Debug, Clone, PartialEq, Eq)]
pub enum Setting<T> {
Set(T),
Reset,
#[default]
NotSet,
}
impl<T> Default for Setting<T> {
fn default() -> Self {
Self::NotSet
}
}
impl<T> Setting<T> {
pub fn map<U, F>(self, f: F) -> Setting<U>
where

View File

@@ -1,9 +1,7 @@
use std::fmt::{self, Display, Formatter};
use std::marker::PhantomData;
use std::str::FromStr;
use serde::de::Visitor;
use serde::{Deserialize, Deserializer};
use serde::Deserialize;
use uuid::Uuid;
use super::settings::{Settings, Unchecked};
@@ -82,59 +80,3 @@ impl Display for IndexUidFormatError {
}
impl std::error::Error for IndexUidFormatError {}
/// A type that tries to match either a star (*) or
/// any other thing that implements `FromStr`.
#[derive(Debug)]
#[cfg_attr(test, derive(serde::Serialize))]
pub enum StarOr<T> {
Star,
Other(T),
}
impl<'de, T, E> Deserialize<'de> for StarOr<T>
where
T: FromStr<Err = E>,
E: Display,
{
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: Deserializer<'de>,
{
/// Serde can't differentiate between `StarOr::Star` and `StarOr::Other` without a tag.
/// Simply using `#[serde(untagged)]` + `#[serde(rename="*")]` will lead to attempting to
/// deserialize everything as a `StarOr::Other`, including "*".
/// [`#[serde(other)]`](https://serde.rs/variant-attrs.html#other) might have helped but is
/// not supported on untagged enums.
struct StarOrVisitor<T>(PhantomData<T>);
impl<T, FE> Visitor<'_> for StarOrVisitor<T>
where
T: FromStr<Err = FE>,
FE: Display,
{
type Value = StarOr<T>;
fn expecting(&self, formatter: &mut Formatter) -> std::fmt::Result {
formatter.write_str("a string")
}
fn visit_str<SE>(self, v: &str) -> Result<Self::Value, SE>
where
SE: serde::de::Error,
{
match v {
"*" => Ok(StarOr::Star),
v => {
let other = FromStr::from_str(v).map_err(|e: T::Err| {
SE::custom(format!("Invalid `other` value: {}", e))
})?;
Ok(StarOr::Other(other))
}
}
}
}
deserializer.deserialize_str(StarOrVisitor(PhantomData))
}
}

View File

@@ -192,19 +192,14 @@ pub struct Facets {
pub min_level_size: Option<NonZeroUsize>,
}
#[derive(Debug, Clone, PartialEq, Eq, Copy)]
#[derive(Default, Debug, Clone, PartialEq, Eq, Copy)]
pub enum Setting<T> {
Set(T),
Reset,
#[default]
NotSet,
}
impl<T> Default for Setting<T> {
fn default() -> Self {
Self::NotSet
}
}
impl<T> Setting<T> {
pub fn set(self) -> Option<T> {
match self {

View File

@@ -47,20 +47,15 @@ pub struct Settings<T> {
pub _kind: PhantomData<T>,
}
#[derive(Debug, Clone, PartialEq, Eq, Copy)]
#[derive(Default, Debug, Clone, PartialEq, Eq, Copy)]
#[cfg_attr(test, derive(serde::Serialize))]
pub enum Setting<T> {
Set(T),
Reset,
#[default]
NotSet,
}
impl<T> Default for Setting<T> {
fn default() -> Self {
Self::NotSet
}
}
impl<T> Setting<T> {
pub fn set(self) -> Option<T> {
match self {

View File

@@ -322,7 +322,7 @@ impl From<Task> for TaskView {
_ => None,
});
let duration = finished_at.zip(started_at).map(|(tf, ts)| (tf - ts));
let duration = finished_at.zip(started_at).map(|(tf, ts)| tf - ts);
Self {
uid: id,

View File

@@ -113,9 +113,9 @@ fn main() {
for op in &operations {
match op {
Either::Left(documents) => {
indexer.replace_documents(documents).unwrap()
}
Either::Left(documents) => indexer
.replace_documents(documents, Default::default())
.unwrap(),
Either::Right(ids) => indexer.delete_documents(ids),
}
}

View File

@@ -164,6 +164,7 @@ impl<'a> Dump<'a> {
content_file: content_uuid.ok_or(Error::CorruptedDump)?,
documents_count,
allow_index_creation,
on_missing_document: Default::default(),
},
KindDump::DocumentDeletion { documents_ids } => KindWithContent::DocumentDeletion {
documents_ids,

View File

@@ -40,6 +40,7 @@ fn doc_imp(
content_file: Uuid::new_v4(),
documents_count: 0,
allow_index_creation,
on_missing_document: Default::default(),
}
}

View File

@@ -2,7 +2,7 @@ use std::fmt;
use std::io::ErrorKind;
use meilisearch_types::heed::RoTxn;
use meilisearch_types::milli::update::IndexDocumentsMethod;
use meilisearch_types::milli::update::{IndexDocumentsMethod, MissingDocumentPolicy};
use meilisearch_types::settings::{Settings, Unchecked};
use meilisearch_types::tasks::{BatchStopReason, Kind, KindWithContent, Status, Task};
use roaring::RoaringBitmap;
@@ -63,8 +63,8 @@ pub(crate) enum Batch {
#[derive(Debug)]
pub(crate) enum DocumentOperation {
Replace(Uuid),
Update(Uuid),
Replace { content_file: Uuid, on_missing_document: MissingDocumentPolicy },
Update { content_file: Uuid, on_missing_document: MissingDocumentPolicy },
Delete(Vec<String>),
}
@@ -293,13 +293,22 @@ impl IndexScheduler {
for task in tasks.iter() {
match task.kind {
KindWithContent::DocumentAdditionOrUpdate {
content_file, method, ..
content_file,
method,
on_missing_document,
..
} => match method {
IndexDocumentsMethod::ReplaceDocuments => {
operations.push(DocumentOperation::Replace(content_file))
operations.push(DocumentOperation::Replace {
content_file,
on_missing_document,
})
}
IndexDocumentsMethod::UpdateDocuments => {
operations.push(DocumentOperation::Update(content_file))
operations.push(DocumentOperation::Update {
content_file,
on_missing_document,
})
}
_ => unreachable!("Unknown document merging method"),
},

View File

@@ -77,8 +77,8 @@ impl IndexScheduler {
let mut content_files = Vec::new();
for operation in &operations {
match operation {
DocumentOperation::Replace(content_uuid)
| DocumentOperation::Update(content_uuid) => {
DocumentOperation::Replace { content_file: content_uuid, .. }
| DocumentOperation::Update { content_file: content_uuid, .. } => {
let content_file = self.queue.file_store.get_update(*content_uuid)?;
let mmap = unsafe { memmap2::Mmap::map(&content_file)? };
content_files.push(mmap);
@@ -100,16 +100,16 @@ impl IndexScheduler {
let embedders = self.embedders(index_uid.clone(), embedders)?;
for operation in operations {
match operation {
DocumentOperation::Replace(_content_uuid) => {
DocumentOperation::Replace { content_file: _, on_missing_document } => {
let mmap = content_files_iter.next().unwrap();
indexer
.replace_documents(mmap)
.replace_documents(mmap, on_missing_document)
.map_err(|e| Error::from_milli(e, Some(index_uid.clone())))?;
}
DocumentOperation::Update(_content_uuid) => {
DocumentOperation::Update { content_file: _, on_missing_document } => {
let mmap = content_files_iter.next().unwrap();
indexer
.update_documents(mmap)
.update_documents(mmap, on_missing_document)
.map_err(|e| Error::from_milli(e, Some(index_uid.clone())))?;
}
DocumentOperation::Delete(document_ids) => {

View File

@@ -294,6 +294,7 @@ fn document_addition_and_index_deletion() {
content_file: uuid,
documents_count,
allow_index_creation: true,
on_missing_document: Default::default(),
},
None,
false,
@@ -482,6 +483,7 @@ fn document_addition_and_index_deletion_on_unexisting_index() {
content_file: uuid,
documents_count,
allow_index_creation: true,
on_missing_document: Default::default(),
},
None,
false,

View File

@@ -31,6 +31,7 @@ fn document_addition() {
content_file: uuid,
documents_count,
allow_index_creation: true,
on_missing_document: Default::default(),
},
None,
false,
@@ -67,6 +68,7 @@ fn document_addition_and_document_deletion() {
content_file: uuid,
documents_count,
allow_index_creation: true,
on_missing_document: Default::default(),
},
None,
false,
@@ -133,6 +135,7 @@ fn document_deletion_and_document_addition() {
content_file: uuid,
documents_count,
allow_index_creation: true,
on_missing_document: Default::default(),
},
None,
false,
@@ -185,6 +188,7 @@ fn test_document_replace() {
content_file: uuid,
documents_count,
allow_index_creation: true,
on_missing_document: Default::default(),
},
None,
false,
@@ -236,6 +240,7 @@ fn test_document_update() {
content_file: uuid,
documents_count,
allow_index_creation: true,
on_missing_document: Default::default(),
},
None,
false,
@@ -289,6 +294,7 @@ fn test_mixed_document_addition() {
content_file: uuid,
documents_count,
allow_index_creation: true,
on_missing_document: Default::default(),
},
None,
false,
@@ -340,6 +346,7 @@ fn test_document_replace_without_autobatching() {
content_file: uuid,
documents_count,
allow_index_creation: true,
on_missing_document: Default::default(),
},
None,
false,
@@ -395,6 +402,7 @@ fn test_document_update_without_autobatching() {
content_file: uuid,
documents_count,
allow_index_creation: true,
on_missing_document: Default::default(),
},
None,
false,
@@ -454,6 +462,7 @@ fn test_document_addition_cant_create_index_without_index() {
content_file: uuid,
documents_count,
allow_index_creation: false,
on_missing_document: Default::default(),
},
None,
false,
@@ -506,6 +515,7 @@ fn test_document_addition_cant_create_index_without_index_without_autobatching()
content_file: uuid,
documents_count,
allow_index_creation: false,
on_missing_document: Default::default(),
},
None,
false,
@@ -568,6 +578,7 @@ fn test_document_addition_cant_create_index_with_index() {
content_file: uuid,
documents_count,
allow_index_creation: false,
on_missing_document: Default::default(),
},
None,
false,
@@ -635,6 +646,7 @@ fn test_document_addition_cant_create_index_with_index_without_autobatching() {
content_file: uuid,
documents_count,
allow_index_creation: false,
on_missing_document: Default::default(),
},
None,
false,
@@ -707,6 +719,7 @@ fn test_document_addition_mixed_rights_with_index() {
content_file: uuid,
documents_count,
allow_index_creation,
on_missing_document: Default::default(),
},
None,
false,
@@ -764,6 +777,7 @@ fn test_document_addition_mixed_right_without_index_starts_with_cant_create() {
content_file: uuid,
documents_count,
allow_index_creation,
on_missing_document: Default::default(),
},
None,
false,
@@ -820,6 +834,7 @@ fn test_document_addition_with_multiple_primary_key() {
content_file: uuid,
documents_count,
allow_index_creation: true,
on_missing_document: Default::default(),
},
None,
false,
@@ -883,6 +898,7 @@ fn test_document_addition_with_multiple_primary_key_batch_wrong_key() {
content_file: uuid,
documents_count,
allow_index_creation: true,
on_missing_document: Default::default(),
},
None,
false,
@@ -943,6 +959,7 @@ fn test_document_addition_with_bad_primary_key() {
content_file: uuid,
documents_count,
allow_index_creation: true,
on_missing_document: Default::default(),
},
None,
false,
@@ -1029,6 +1046,7 @@ fn test_document_addition_with_set_and_null_primary_key() {
content_file: uuid,
documents_count,
allow_index_creation: true,
on_missing_document: Default::default(),
},
None,
false,
@@ -1104,6 +1122,7 @@ fn test_document_addition_with_set_and_null_primary_key_inference_works() {
content_file: uuid,
documents_count,
allow_index_creation: true,
on_missing_document: Default::default(),
},
None,
false,

View File

@@ -173,6 +173,7 @@ fn import_vectors() {
content_file: uuid,
documents_count,
allow_index_creation: true,
on_missing_document: Default::default(),
},
None,
false,
@@ -263,6 +264,7 @@ fn import_vectors() {
content_file: uuid,
documents_count,
allow_index_creation: true,
on_missing_document: Default::default(),
},
None,
false,
@@ -399,6 +401,7 @@ fn import_vectors_first_and_embedder_later() {
content_file: uuid,
documents_count,
allow_index_creation: true,
on_missing_document: Default::default(),
},
None,
false,
@@ -539,6 +542,7 @@ fn import_vectors_first_and_embedder_later() {
content_file: uuid,
documents_count,
allow_index_creation: true,
on_missing_document: Default::default(),
},
None,
false,
@@ -640,6 +644,7 @@ fn delete_document_containing_vector() {
content_file: uuid,
documents_count,
allow_index_creation: false,
on_missing_document: Default::default(),
},
None,
false,
@@ -818,6 +823,7 @@ fn delete_embedder_with_user_provided_vectors() {
content_file: uuid,
documents_count,
allow_index_creation: false,
on_missing_document: Default::default(),
},
None,
false,

View File

@@ -52,6 +52,7 @@ fn fail_in_process_batch_for_document_addition() {
content_file: uuid,
documents_count,
allow_index_creation: true,
on_missing_document: Default::default(),
},
None,
false,
@@ -94,6 +95,7 @@ fn fail_in_update_task_after_process_batch_success_for_document_addition() {
content_file: uuid,
documents_count,
allow_index_creation: true,
on_missing_document: Default::default(),
},
None,
false,
@@ -160,6 +162,7 @@ fn fail_in_process_batch_for_document_deletion() {
content_file: uuid,
documents_count,
allow_index_creation: true,
on_missing_document: Default::default(),
},
None,
false,

View File

@@ -197,6 +197,7 @@ pub(crate) fn replace_document_import_task(
content_file: Uuid::from_u128(content_file_uuid),
documents_count,
allow_index_creation: true,
on_missing_document: Default::default(),
}
}

View File

@@ -255,6 +255,7 @@ InvalidIndexLimit , InvalidRequest , BAD_REQU
InvalidIndexOffset , InvalidRequest , BAD_REQUEST ;
InvalidIndexPrimaryKey , InvalidRequest , BAD_REQUEST ;
InvalidIndexCustomMetadata , InvalidRequest , BAD_REQUEST ;
InvalidSkipCreation , InvalidRequest , BAD_REQUEST ;
InvalidIndexUid , InvalidRequest , BAD_REQUEST ;
InvalidMultiSearchFacets , InvalidRequest , BAD_REQUEST ;
InvalidMultiSearchFacetsByIndex , InvalidRequest , BAD_REQUEST ;

View File

@@ -5,7 +5,7 @@ use std::str::FromStr;
use byte_unit::Byte;
use enum_iterator::Sequence;
use milli::update::IndexDocumentsMethod;
use milli::update::{IndexDocumentsMethod, MissingDocumentPolicy};
use milli::Object;
use roaring::RoaringBitmap;
use serde::{Deserialize, Serialize, Serializer};
@@ -114,6 +114,7 @@ pub enum KindWithContent {
content_file: Uuid,
documents_count: u64,
allow_index_creation: bool,
on_missing_document: MissingDocumentPolicy,
},
DocumentDeletion {
index_uid: String,

View File

@@ -1,7 +1,7 @@
use std::any::TypeId;
use std::collections::{HashMap, HashSet};
use std::fs;
use std::path::{Path, PathBuf};
use std::path::Path;
use std::sync::Arc;
use std::time::{Duration, Instant};
@@ -344,14 +344,14 @@ impl Infos {
experimental_no_edition_2024_for_dumps,
experimental_vector_store_setting: vector_store_setting,
gpu_enabled: meilisearch_types::milli::vector::is_cuda_enabled(),
db_path: db_path != PathBuf::from("./data.ms"),
db_path: db_path != Path::new("./data.ms"),
import_dump: import_dump.is_some(),
dump_dir: dump_dir != PathBuf::from("dumps/"),
dump_dir: dump_dir != Path::new("dumps/"),
ignore_missing_dump,
ignore_dump_if_db_exists,
import_snapshot: import_snapshot.is_some(),
schedule_snapshot,
snapshot_dir: snapshot_dir != PathBuf::from("snapshots/"),
snapshot_dir: snapshot_dir != Path::new("snapshots/"),
uses_s3_snapshots: s3_snapshot_options.is_some(),
ignore_missing_snapshot,
ignore_snapshot_if_db_exists,

View File

@@ -629,7 +629,7 @@ fn import_dump(
let mmap = unsafe { memmap2::Mmap::map(index_reader.documents_file())? };
indexer.replace_documents(&mmap)?;
indexer.replace_documents(&mmap, Default::default())?;
let indexer_config = index_scheduler.indexer_config();
let pool = &indexer_config.thread_pool;

View File

@@ -20,7 +20,7 @@ use meilisearch_types::heed::RoTxn;
use meilisearch_types::index_uid::IndexUid;
use meilisearch_types::milli::documents::sort::recursive_sort;
use meilisearch_types::milli::index::EmbeddingsWithMetadata;
use meilisearch_types::milli::update::IndexDocumentsMethod;
use meilisearch_types::milli::update::{IndexDocumentsMethod, MissingDocumentPolicy};
use meilisearch_types::milli::vector::parsed_vectors::ExplicitVectors;
use meilisearch_types::milli::{AscDesc, DocumentId};
use meilisearch_types::serde_cs::vec::CS;
@@ -687,6 +687,11 @@ pub struct UpdateDocumentsQuery {
#[param(example = "custom")]
#[deserr(default, error = DeserrQueryParamError<InvalidIndexCustomMetadata>)]
pub custom_metadata: Option<String>,
#[param(example = "true")]
#[deserr(default, try_from(&String) = from_string_skip_creation -> DeserrQueryParamError<InvalidSkipCreation>, error = DeserrQueryParamError<InvalidSkipCreation>)]
/// Only update documents if they already exist.
pub skip_creation: Option<bool>,
}
#[derive(Deserialize, Debug, Deserr, IntoParams)]
@@ -711,6 +716,23 @@ fn from_char_csv_delimiter(
}
}
fn from_string_skip_creation(
s: &String,
) -> Result<Option<bool>, DeserrQueryParamError<InvalidSkipCreation>> {
if s.eq_ignore_ascii_case("true") {
return Ok(Some(true));
}
if s.eq_ignore_ascii_case("false") {
return Ok(Some(false));
}
Err(DeserrQueryParamError::new(
format!("skipCreation must be either `true` or `false`. Found: `{}`", s),
Code::InvalidSkipCreation,
))
}
aggregate_methods!(
Replaced => "Documents Added",
Updated => "Documents Updated",
@@ -840,6 +862,7 @@ pub async fn replace_documents(
params.custom_metadata,
dry_run,
allow_index_creation,
params.skip_creation,
&req,
)
.await?;
@@ -943,6 +966,7 @@ pub async fn update_documents(
params.custom_metadata,
dry_run,
allow_index_creation,
params.skip_creation,
&req,
)
.await?;
@@ -963,6 +987,7 @@ async fn document_addition(
custom_metadata: Option<String>,
dry_run: bool,
allow_index_creation: bool,
skip_creation: Option<bool>,
req: &HttpRequest,
) -> Result<SummarizedTaskView, MeilisearchHttpError> {
let mime_type = extract_mime_type(req)?;
@@ -1083,6 +1108,11 @@ async fn document_addition(
primary_key,
allow_index_creation,
index_uid: index_uid.to_string(),
on_missing_document: if matches!(skip_creation, Some(true)) {
MissingDocumentPolicy::Skip
} else {
MissingDocumentPolicy::Create
},
};
let scheduler = index_scheduler.clone();

View File

@@ -789,11 +789,12 @@ impl TryFrom<Value> for ExternalDocumentId {
}
}
#[derive(Debug, Copy, Clone, PartialEq, Eq, Deserr, ToSchema, Serialize)]
#[derive(Default, Debug, Copy, Clone, PartialEq, Eq, Deserr, ToSchema, Serialize)]
#[deserr(rename_all = camelCase)]
#[serde(rename_all = "camelCase")]
pub enum MatchingStrategy {
/// Remove query words from last to first
#[default]
Last,
/// All query words are mandatory
All,
@@ -801,12 +802,6 @@ pub enum MatchingStrategy {
Frequency,
}
impl Default for MatchingStrategy {
fn default() -> Self {
Self::Last
}
}
impl From<MatchingStrategy> for TermsMatchingStrategy {
fn from(other: MatchingStrategy) -> Self {
match other {

View File

@@ -187,7 +187,7 @@ macro_rules! compute_forbidden_search {
#[actix_rt::test]
async fn search_authorized_simple_token() {
let tenant_tokens = vec![
let tenant_tokens = [
hashmap! {
"searchRules" => json!({"*": {}}),
"exp" => json!((OffsetDateTime::now_utc() + Duration::hours(1)).unix_timestamp())
@@ -239,7 +239,7 @@ async fn search_authorized_simple_token() {
#[actix_rt::test]
async fn search_authorized_filter_token() {
let tenant_tokens = vec![
let tenant_tokens = [
hashmap! {
"searchRules" => json!({"*": {"filter": "color = blue"}}),
"exp" => json!((OffsetDateTime::now_utc() + Duration::hours(1)).unix_timestamp())
@@ -292,7 +292,7 @@ async fn search_authorized_filter_token() {
#[actix_rt::test]
async fn filter_search_authorized_filter_token() {
let tenant_tokens = vec![
let tenant_tokens = [
hashmap! {
"searchRules" => json!({"*": {"filter": "color = blue"}}),
"exp" => json!((OffsetDateTime::now_utc() + Duration::hours(1)).unix_timestamp())
@@ -353,7 +353,7 @@ async fn filter_search_authorized_filter_token() {
/// Tests that those Tenant Token are incompatible with the REFUSED_KEYS defined above.
#[actix_rt::test]
async fn error_search_token_forbidden_parent_key() {
let tenant_tokens = vec![
let tenant_tokens = [
hashmap! {
"searchRules" => json!({"*": {}}),
"exp" => json!((OffsetDateTime::now_utc() + Duration::hours(1)).unix_timestamp())
@@ -389,7 +389,7 @@ async fn error_search_token_forbidden_parent_key() {
#[actix_rt::test]
async fn error_search_forbidden_token() {
let tenant_tokens = vec![
let tenant_tokens = [
// bad index
hashmap! {
"searchRules" => json!({"products": {}}),

View File

@@ -680,7 +680,7 @@ async fn multi_search_authorized_simple_token() {
#[actix_rt::test]
async fn single_search_authorized_filter_token() {
let tenant_tokens = vec![
let tenant_tokens = [
hashmap! {
"searchRules" => json!({"*": {"filter": "color = blue"}}),
"exp" => json!((OffsetDateTime::now_utc() + Duration::hours(1)).unix_timestamp())
@@ -733,7 +733,7 @@ async fn single_search_authorized_filter_token() {
#[actix_rt::test]
async fn multi_search_authorized_filter_token() {
let both_tenant_tokens = vec![
let both_tenant_tokens = [
hashmap! {
"searchRules" => json!({"sales": {"filter": "color = blue"}, "products": {"filter": "doggos.age <= 5"}}),
"exp" => json!((OffsetDateTime::now_utc() + Duration::hours(1)).unix_timestamp())
@@ -842,7 +842,7 @@ async fn filter_single_search_authorized_filter_token() {
#[actix_rt::test]
async fn filter_multi_search_authorized_filter_token() {
let tenant_tokens = vec![
let tenant_tokens = [
hashmap! {
"searchRules" => json!({"sales": {"filter": "color = blue"}, "products": {"filter": "doggos.age <= 5"}}),
"exp" => json!((OffsetDateTime::now_utc() + Duration::hours(1)).unix_timestamp())
@@ -900,7 +900,7 @@ async fn filter_multi_search_authorized_filter_token() {
/// Tests that those Tenant Token are incompatible with the REFUSED_KEYS defined above.
#[actix_rt::test]
async fn error_single_search_token_forbidden_parent_key() {
let tenant_tokens = vec![
let tenant_tokens = [
hashmap! {
"searchRules" => json!({"*": {}}),
"exp" => json!((OffsetDateTime::now_utc() + Duration::hours(1)).unix_timestamp())
@@ -941,7 +941,7 @@ async fn error_single_search_token_forbidden_parent_key() {
/// Tests that those Tenant Token are incompatible with the REFUSED_KEYS defined above.
#[actix_rt::test]
async fn error_multi_search_token_forbidden_parent_key() {
let tenant_tokens = vec![
let tenant_tokens = [
hashmap! {
"searchRules" => json!({"*": {}}),
"exp" => json!((OffsetDateTime::now_utc() + Duration::hours(1)).unix_timestamp())

View File

@@ -385,9 +385,10 @@ pub struct SearchResult {
pub query_vector: Option<Embedding>,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[derive(Default, Debug, Clone, Copy, PartialEq, Eq)]
pub enum TermsMatchingStrategy {
// remove last word first
#[default]
Last,
// all words are mandatory
All,
@@ -395,12 +396,6 @@ pub enum TermsMatchingStrategy {
Frequency,
}
impl Default for TermsMatchingStrategy {
fn default() -> Self {
Self::Last
}
}
impl From<MatchingStrategy> for TermsMatchingStrategy {
fn from(other: MatchingStrategy) -> Self {
match other {

View File

@@ -64,7 +64,7 @@ pub fn setup_search_index_with_criteria(criteria: &[Criterion]) -> Index {
let payload = unsafe { memmap2::Mmap::map(&file).unwrap() };
// index documents
indexer.replace_documents(&payload).unwrap();
indexer.replace_documents(&payload, Default::default()).unwrap();
let indexer_alloc = Bump::new();
let (document_changes, operation_stats, primary_key) = indexer

View File

@@ -70,9 +70,11 @@ impl TempIndex {
let mut indexer = indexer::DocumentOperation::new();
match self.index_documents_config.update_method {
IndexDocumentsMethod::ReplaceDocuments => {
indexer.replace_documents(&documents).unwrap()
indexer.replace_documents(&documents, Default::default()).unwrap()
}
IndexDocumentsMethod::UpdateDocuments => {
indexer.update_documents(&documents, Default::default()).unwrap()
}
IndexDocumentsMethod::UpdateDocuments => indexer.update_documents(&documents).unwrap(),
}
let indexer_alloc = Bump::new();
@@ -232,7 +234,7 @@ fn aborting_indexation() {
{ "id": 2, "name": "bob", "age": 20 },
{ "id": 2, "name": "bob", "age": 20 },
]);
indexer.replace_documents(&payload).unwrap();
indexer.replace_documents(&payload, Default::default()).unwrap();
let indexer_alloc = Bump::new();
let (document_changes, _operation_stats, primary_key) = indexer

View File

@@ -124,7 +124,7 @@ impl GrenadParameters {
/// This should be called inside of a rayon thread pool,
/// otherwise, it will take the global number of threads.
pub fn max_memory_by_thread(&self) -> Option<usize> {
self.max_memory.map(|max_memory| (max_memory / rayon::current_num_threads()))
self.max_memory.map(|max_memory| max_memory / rayon::current_num_threads())
}
}

View File

@@ -54,11 +54,12 @@ pub struct DocumentAdditionResult {
pub number_of_documents: u64,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
#[derive(Default, Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
#[non_exhaustive]
pub enum IndexDocumentsMethod {
/// Replace the previous document with the new one,
/// removing all the already known attributes.
#[default]
ReplaceDocuments,
/// Merge the previous version of the document with the new version,
@@ -66,10 +67,19 @@ pub enum IndexDocumentsMethod {
UpdateDocuments,
}
impl Default for IndexDocumentsMethod {
fn default() -> Self {
Self::ReplaceDocuments
}
/// Controls whether new documents should be created when they don't already exist.
///
/// This policy is checked when processing a document whose ID is not found in the index.
/// It applies to both update and replace operations.
#[derive(Default, Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub enum MissingDocumentPolicy {
/// Create the document if it doesn't exist. This is the default behavior.
#[default]
Create,
/// Skip the document silently if it doesn't exist. No error is returned, the document is simply
/// not indexed.
Skip,
}
pub struct IndexDocuments<'t, 'i, 'a, FP, FA> {
@@ -1976,10 +1986,10 @@ mod tests {
let mut new_fields_ids_map = db_fields_ids_map.clone();
let mut indexer = indexer::DocumentOperation::new();
indexer.replace_documents(&doc1).unwrap();
indexer.replace_documents(&doc2).unwrap();
indexer.replace_documents(&doc3).unwrap();
indexer.replace_documents(&doc4).unwrap();
indexer.replace_documents(&doc1, Default::default()).unwrap();
indexer.replace_documents(&doc2, Default::default()).unwrap();
indexer.replace_documents(&doc3, Default::default()).unwrap();
indexer.replace_documents(&doc4, Default::default()).unwrap();
let indexer_alloc = Bump::new();
let (_document_changes, operation_stats, _primary_key) = indexer
@@ -2029,10 +2039,10 @@ mod tests {
let mut new_fields_ids_map = db_fields_ids_map.clone();
let mut indexer = indexer::DocumentOperation::new();
indexer.replace_documents(&doc1).unwrap();
indexer.update_documents(&doc2).unwrap();
indexer.update_documents(&doc3).unwrap();
indexer.update_documents(&doc4).unwrap();
indexer.replace_documents(&doc1, Default::default()).unwrap();
indexer.update_documents(&doc2, Default::default()).unwrap();
indexer.update_documents(&doc3, Default::default()).unwrap();
indexer.update_documents(&doc4, Default::default()).unwrap();
let indexer_alloc = Bump::new();
let (document_changes, operation_stats, primary_key) = indexer
@@ -2117,11 +2127,11 @@ mod tests {
let mut new_fields_ids_map = db_fields_ids_map.clone();
let mut indexer = indexer::DocumentOperation::new();
indexer.replace_documents(&doc1).unwrap();
indexer.update_documents(&doc2).unwrap();
indexer.update_documents(&doc3).unwrap();
indexer.replace_documents(&doc4).unwrap();
indexer.update_documents(&doc5).unwrap();
indexer.replace_documents(&doc1, Default::default()).unwrap();
indexer.update_documents(&doc2, Default::default()).unwrap();
indexer.update_documents(&doc3, Default::default()).unwrap();
indexer.replace_documents(&doc4, Default::default()).unwrap();
indexer.update_documents(&doc5, Default::default()).unwrap();
let indexer_alloc = Bump::new();
let (document_changes, operation_stats, primary_key) = indexer
@@ -2312,7 +2322,7 @@ mod tests {
let indexer_alloc = Bump::new();
let embedders = RuntimeEmbedders::default();
let mut indexer = indexer::DocumentOperation::new();
indexer.replace_documents(&documents).unwrap();
indexer.replace_documents(&documents, Default::default()).unwrap();
indexer.delete_documents(&["2"]);
let (document_changes, _operation_stats, primary_key) = indexer
.into_changes(
@@ -2367,13 +2377,13 @@ mod tests {
{ "id": 3, "name": "jean", "age": 25 },
]);
let mut indexer = indexer::DocumentOperation::new();
indexer.update_documents(&documents).unwrap();
indexer.update_documents(&documents, Default::default()).unwrap();
let documents = documents!([
{ "id": 2, "catto": "jorts" },
{ "id": 3, "legs": 4 },
]);
indexer.update_documents(&documents).unwrap();
indexer.update_documents(&documents, Default::default()).unwrap();
indexer.delete_documents(&["1", "2"]);
let indexer_alloc = Bump::new();
@@ -2431,7 +2441,7 @@ mod tests {
let indexer_alloc = Bump::new();
let embedders = RuntimeEmbedders::default();
let mut indexer = indexer::DocumentOperation::new();
indexer.update_documents(&documents).unwrap();
indexer.update_documents(&documents, Default::default()).unwrap();
let (document_changes, _operation_stats, primary_key) = indexer
.into_changes(
@@ -2484,7 +2494,7 @@ mod tests {
let indexer_alloc = Bump::new();
let embedders = RuntimeEmbedders::default();
let mut indexer = indexer::DocumentOperation::new();
indexer.update_documents(&documents).unwrap();
indexer.update_documents(&documents, Default::default()).unwrap();
indexer.delete_documents(&["1", "2"]);
let (document_changes, _operation_stats, primary_key) = indexer
@@ -2541,7 +2551,7 @@ mod tests {
{ "id": 2, "doggo": { "name": "jean", "age": 20 } },
{ "id": 3, "name": "bob", "age": 25 },
]);
indexer.update_documents(&documents).unwrap();
indexer.update_documents(&documents, Default::default()).unwrap();
let (document_changes, _operation_stats, primary_key) = indexer
.into_changes(
@@ -2600,7 +2610,7 @@ mod tests {
{ "id": 2, "doggo": { "name": "jean", "age": 20 } },
{ "id": 3, "name": "bob", "age": 25 },
]);
indexer.update_documents(&documents).unwrap();
indexer.update_documents(&documents, Default::default()).unwrap();
indexer.delete_documents(&["1", "2", "1", "2"]);
@@ -2656,7 +2666,7 @@ mod tests {
let documents = documents!([
{ "id": 1, "doggo": "kevin" },
]);
indexer.update_documents(&documents).unwrap();
indexer.update_documents(&documents, Default::default()).unwrap();
let (document_changes, _operation_stats, primary_key) = indexer
.into_changes(
@@ -2710,7 +2720,7 @@ mod tests {
{ "id": 1, "catto": "jorts" },
]);
indexer.replace_documents(&documents).unwrap();
indexer.replace_documents(&documents, Default::default()).unwrap();
let (document_changes, _operation_stats, primary_key) = indexer
.into_changes(
@@ -2921,7 +2931,7 @@ mod tests {
let documents = documents!([
{ "id": 1, "doggo": "bernese" },
]);
indexer.replace_documents(&documents).unwrap();
indexer.replace_documents(&documents, Default::default()).unwrap();
// FINISHING
let (document_changes, _operation_stats, primary_key) = indexer
@@ -2983,7 +2993,7 @@ mod tests {
let documents = documents!([
{ "id": 0, "catto": "jorts" },
]);
indexer.replace_documents(&documents).unwrap();
indexer.replace_documents(&documents, Default::default()).unwrap();
let (document_changes, _operation_stats, primary_key) = indexer
.into_changes(
@@ -3041,7 +3051,7 @@ mod tests {
let documents = documents!([
{ "id": 1, "catto": "jorts" },
]);
indexer.replace_documents(&documents).unwrap();
indexer.replace_documents(&documents, Default::default()).unwrap();
let (document_changes, _operation_stats, primary_key) = indexer
.into_changes(

View File

@@ -21,7 +21,7 @@ use crate::update::new::indexer::current_edition::sharding::Shards;
use crate::update::new::steps::IndexingStep;
use crate::update::new::thread_local::MostlySend;
use crate::update::new::{DocumentIdentifiers, Insertion, Update};
use crate::update::{AvailableIds, IndexDocumentsMethod};
use crate::update::{AvailableIds, IndexDocumentsMethod, MissingDocumentPolicy};
use crate::{DocumentId, Error, FieldsIdsMap, Index, InternalError, Result, UserError};
#[derive(Default)]
@@ -37,20 +37,28 @@ impl<'pl> DocumentOperation<'pl> {
/// Append a replacement of documents.
///
/// The payload is expected to be in the NDJSON format
pub fn replace_documents(&mut self, payload: &'pl Mmap) -> Result<()> {
pub fn replace_documents(
&mut self,
payload: &'pl Mmap,
on_missing_document: MissingDocumentPolicy,
) -> Result<()> {
#[cfg(unix)]
payload.advise(memmap2::Advice::Sequential)?;
self.operations.push(Payload::Replace(&payload[..]));
self.operations.push(Payload::Replace { payload: &payload[..], on_missing_document });
Ok(())
}
/// Append an update of documents.
///
/// The payload is expected to be in the NDJSON format
pub fn update_documents(&mut self, payload: &'pl Mmap) -> Result<()> {
pub fn update_documents(
&mut self,
payload: &'pl Mmap,
on_missing_document: MissingDocumentPolicy,
) -> Result<()> {
#[cfg(unix)]
payload.advise(memmap2::Advice::Sequential)?;
self.operations.push(Payload::Update(&payload[..]));
self.operations.push(Payload::Update { payload: &payload[..], on_missing_document });
Ok(())
}
@@ -98,34 +106,40 @@ impl<'pl> DocumentOperation<'pl> {
let mut bytes = 0;
let result = match operation {
Payload::Replace(payload) => extract_addition_payload_changes(
indexer,
index,
rtxn,
primary_key_from_op,
&mut primary_key,
new_fields_ids_map,
&mut available_docids,
&mut bytes,
&docids_version_offsets,
IndexDocumentsMethod::ReplaceDocuments,
shards,
payload,
),
Payload::Update(payload) => extract_addition_payload_changes(
indexer,
index,
rtxn,
primary_key_from_op,
&mut primary_key,
new_fields_ids_map,
&mut available_docids,
&mut bytes,
&docids_version_offsets,
IndexDocumentsMethod::UpdateDocuments,
shards,
payload,
),
Payload::Replace { payload, on_missing_document } => {
extract_addition_payload_changes(
indexer,
index,
rtxn,
primary_key_from_op,
&mut primary_key,
new_fields_ids_map,
&mut available_docids,
&mut bytes,
&docids_version_offsets,
IndexDocumentsMethod::ReplaceDocuments,
shards,
payload,
on_missing_document,
)
}
Payload::Update { payload, on_missing_document } => {
extract_addition_payload_changes(
indexer,
index,
rtxn,
primary_key_from_op,
&mut primary_key,
new_fields_ids_map,
&mut available_docids,
&mut bytes,
&docids_version_offsets,
IndexDocumentsMethod::UpdateDocuments,
shards,
payload,
on_missing_document,
)
}
Payload::Deletion(to_delete) => extract_deletion_payload_changes(
index,
rtxn,
@@ -180,6 +194,7 @@ fn extract_addition_payload_changes<'r, 'pl: 'r>(
method: IndexDocumentsMethod,
shards: Option<&Shards>,
payload: &'pl [u8],
on_missing_document: MissingDocumentPolicy,
) -> Result<hashbrown::HashMap<&'pl str, PayloadOperations<'pl>>> {
use IndexDocumentsMethod::{ReplaceDocuments, UpdateDocuments};
@@ -271,6 +286,10 @@ fn extract_addition_payload_changes<'r, 'pl: 'r>(
match method {
ReplaceDocuments => {
if matches!(on_missing_document, MissingDocumentPolicy::Skip) {
continue;
}
entry.insert(PayloadOperations::new_replacement(
docid,
true, // is new
@@ -278,6 +297,10 @@ fn extract_addition_payload_changes<'r, 'pl: 'r>(
));
}
UpdateDocuments => {
if matches!(on_missing_document, MissingDocumentPolicy::Skip) {
continue;
}
entry.insert(PayloadOperations::new_update(
docid,
true, // is new
@@ -297,6 +320,12 @@ fn extract_addition_payload_changes<'r, 'pl: 'r>(
},
Entry::Vacant(entry) => match method {
ReplaceDocuments => {
if payload_operations.is_new
&& matches!(on_missing_document, MissingDocumentPolicy::Skip)
{
continue;
}
entry.insert(PayloadOperations::new_replacement(
payload_operations.docid,
payload_operations.is_new,
@@ -304,6 +333,12 @@ fn extract_addition_payload_changes<'r, 'pl: 'r>(
));
}
UpdateDocuments => {
if payload_operations.is_new
&& matches!(on_missing_document, MissingDocumentPolicy::Skip)
{
continue;
}
entry.insert(PayloadOperations::new_update(
payload_operations.docid,
payload_operations.is_new,
@@ -448,8 +483,8 @@ pub struct DocumentOperationChanges<'pl> {
}
pub enum Payload<'pl> {
Replace(&'pl [u8]),
Update(&'pl [u8]),
Replace { payload: &'pl [u8], on_missing_document: MissingDocumentPolicy },
Update { payload: &'pl [u8], on_missing_document: MissingDocumentPolicy },
Deletion(&'pl [&'pl str]),
}

View File

@@ -48,10 +48,11 @@ use crate::{
ChannelCongestion, FieldId, FilterableAttributesRule, Index, LocalizedAttributesRule, Result,
};
#[derive(Debug, Clone, PartialEq, Eq, Copy)]
#[derive(Default, Debug, Clone, PartialEq, Eq, Copy)]
pub enum Setting<T> {
Set(T),
Reset,
#[default]
NotSet,
}
@@ -71,12 +72,6 @@ where
}
}
impl<T> Default for Setting<T> {
fn default() -> Self {
Self::NotSet
}
}
impl<T> Setting<T> {
pub fn set(self) -> Option<T> {
match self {

View File

@@ -67,7 +67,7 @@ impl<F> Embeddings<F> {
///
/// If `embeddings.len() % self.dimension != 0`, then the append operation fails.
pub fn append(&mut self, mut embeddings: Vec<F>) -> Result<(), Vec<F>> {
if embeddings.len() % self.dimension != 0 {
if !embeddings.len().is_multiple_of(self.dimension) {
return Err(embeddings);
}
self.data.append(&mut embeddings);

View File

@@ -47,7 +47,7 @@ fn test_facet_distribution_with_no_facet_values() {
let documents = mmap_from_objects(vec![doc1, doc2]);
// index documents
indexer.replace_documents(&documents).unwrap();
indexer.replace_documents(&documents, Default::default()).unwrap();
let indexer_alloc = Bump::new();
let (document_changes, _operation_stats, primary_key) = indexer

View File

@@ -85,7 +85,7 @@ pub fn setup_search_index_with_criteria(criteria: &[Criterion]) -> Index {
let payload = unsafe { memmap2::Mmap::map(&file).unwrap() };
// index documents
indexer.replace_documents(&payload).unwrap();
indexer.replace_documents(&payload, Default::default()).unwrap();
let indexer_alloc = Bump::new();
let (document_changes, operation_stats, primary_key) = indexer

View File

@@ -319,7 +319,7 @@ fn criteria_ascdesc() {
file.sync_all().unwrap();
let payload = unsafe { memmap2::Mmap::map(&file).unwrap() };
indexer.replace_documents(&payload).unwrap();
indexer.replace_documents(&payload, Default::default()).unwrap();
let (document_changes, _operation_stats, primary_key) = indexer
.into_changes(
&indexer_alloc,

View File

@@ -126,7 +126,7 @@ fn test_typo_disabled_on_word() {
let embedders = RuntimeEmbedders::default();
let mut indexer = indexer::DocumentOperation::new();
indexer.replace_documents(&documents).unwrap();
indexer.replace_documents(&documents, Default::default()).unwrap();
let indexer_alloc = Bump::new();
let (document_changes, _operation_stats, primary_key) = indexer

View File

@@ -178,6 +178,7 @@ pub fn get_arch() -> anyhow::Result<&'static str> {
#[cfg(not(all(target_os = "linux", target_arch = "aarch64")))]
#[cfg(not(all(target_os = "linux", target_arch = "x86_64")))]
#[cfg(not(all(target_os = "macos", target_arch = "aarch64")))]
#[cfg(not(all(target_os = "macos", target_arch = "x86_64")))]
anyhow::bail!("unsupported platform")
}

View File

@@ -1,3 +1,3 @@
[toolchain]
channel = "1.89.0"
channel = "1.91.1"
components = ["clippy"]