Skip to content

Commit

Permalink
chore: remove prefilter, stand-alone-test and default feature (#505)
Browse files Browse the repository at this point in the history
* chore: remove prefilter, stand-alone-test and default feature

Signed-off-by: usamoi <usamoi@outlook.com>

* fix: simplify hnsw entry

Signed-off-by: usamoi <usamoi@outlook.com>

---------

Signed-off-by: usamoi <usamoi@outlook.com>
  • Loading branch information
usamoi authored Jun 20, 2024
1 parent 1a9e0b6 commit 4360cac
Show file tree
Hide file tree
Showing 29 changed files with 127 additions and 1,208 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/psql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@ jobs:
echo PGRX_TARGET_INFO_PATH_PG$VERSION=$HOME/.pgrx_binding >> "$GITHUB_ENV"
- name: Build Release
run: |
cargo build --lib --no-default-features --features "pg$VERSION" --release
./tools/schema.sh --no-default-features --features "pg$VERSION" --release | expand -t 4 > ./target/vectors--$SEMVER.sql
cargo build --lib --features "pg$VERSION" --release
./tools/schema.sh --features "pg$VERSION" --release | expand -t 4 > ./target/vectors--$SEMVER.sql
- name: Set up PostgreSQL
run: |
sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" >> /etc/apt/sources.list.d/pgdg.list'
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ jobs:
echo PGRX_TARGET_INFO_PATH_PG$VERSION=$HOME/.pgrx_binding >> "$GITHUB_ENV"
- name: Build
run: |
cargo build --lib --no-default-features --features pg$VERSION --release --target $ARCH-unknown-linux-gnu
./tools/schema.sh --no-default-features --features pg$VERSION --release --target $ARCH-unknown-linux-gnu | expand -t 4 > ./target/vectors--$SEMVER.sql
cargo build --lib --features pg$VERSION --release --target $ARCH-unknown-linux-gnu
./tools/schema.sh --features pg$VERSION --release --target $ARCH-unknown-linux-gnu | expand -t 4 > ./target/vectors--$SEMVER.sql
- name: Package
run: |
export PLATFORM=$(echo $ARCH | sed 's/aarch64/arm64/; s/x86_64/amd64/')
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,9 @@ jobs:
cp ./vendor/pgrx_binding/pg${VERSION}_$(uname --machine)-unknown-linux-gnu.rs ~/.pgrx_binding/pg${VERSION}_raw_bindings.rs
echo PGRX_TARGET_INFO_PATH_PG$VERSION=$HOME/.pgrx_binding >> "$GITHUB_ENV"
- name: Clippy
run: cargo clippy --no-default-features --features "pg$VERSION" --target $ARCH-unknown-linux-gnu
run: cargo clippy --features "pg$VERSION" --target $ARCH-unknown-linux-gnu
- name: Build
run: cargo build --lib --no-default-features --features "pg$VERSION" --target $ARCH-unknown-linux-gnu
run: cargo build --lib --features "pg$VERSION" --target $ARCH-unknown-linux-gnu
- name: Post Set up Cache
uses: actions/cache/save@v4
if: ${{ !steps.cache.outputs.cache-hit }}
Expand Down Expand Up @@ -163,14 +163,14 @@ jobs:
cp ./vendor/pgrx_binding/pg${VERSION}_$(uname --machine)-unknown-linux-gnu.rs ~/.pgrx_binding/pg${VERSION}_raw_bindings.rs
echo PGRX_TARGET_INFO_PATH_PG$VERSION=$HOME/.pgrx_binding >> "$GITHUB_ENV"
- name: Test
run: cargo test --all --no-fail-fast --no-default-features --features "pg$VERSION" --target $ARCH-unknown-linux-gnu -- --nocapture
run: cargo test --all --no-fail-fast --features "pg$VERSION" --target $ARCH-unknown-linux-gnu -- --nocapture
- name: Test (x86_64)
if: matrix.arch == 'x86_64'
run: |
ASSETS=$(mktemp -d)
wget https://downloadmirror.intel.com/813591/sde-external-9.33.0-2024-01-07-lin.tar.xz -O $ASSETS/sde-external.tar.xz
tar -xf $ASSETS/sde-external.tar.xz -C $ASSETS
cargo --config "target.x86_64-unknown-linux-gnu.runner = [\"$ASSETS/sde-external-9.33.0-2024-01-07-lin/sde64\", \"-spr\", \"--\"]" test "_v4" --all --no-fail-fast --no-default-features --features "pg$VERSION" --target $ARCH-unknown-linux-gnu -- --nocapture
cargo --config "target.x86_64-unknown-linux-gnu.runner = [\"$ASSETS/sde-external-9.33.0-2024-01-07-lin/sde64\", \"-spr\", \"--\"]" test "_v4" --all --no-fail-fast --features "pg$VERSION" --target $ARCH-unknown-linux-gnu -- --nocapture
- name: Post Set up Cache
uses: actions/cache/save@v4
if: ${{ !steps.cache.outputs.cache-hit }}
Expand Down
61 changes: 0 additions & 61 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ name = "pgrx_embed_vectors"
path = "./src/bin/pgrx_embed.rs"

[features]
default = ["pg15"]
default = []
pg14 = ["pgrx/pg14"]
pg15 = ["pgrx/pg15"]
pg16 = ["pgrx/pg16"]
Expand Down
1 change: 0 additions & 1 deletion crates/base/src/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,6 @@ impl Default for ProductQuantizationOptionsRatio {

#[derive(Debug, Clone, Serialize, Deserialize, Validate)]
pub struct SearchOptions {
pub prefilter_enable: bool,
#[validate(range(min = 1, max = 65535))]
pub hnsw_ef_search: u32,
#[validate(range(min = 1, max = 1_000_000))]
Expand Down
4 changes: 0 additions & 4 deletions crates/base/src/search.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,6 @@ pub struct Element {
pub payload: Payload,
}

pub trait Filter: Clone {
fn check(&mut self, payload: Payload) -> bool;
}

pub trait Collection<O: Operator> {
fn dims(&self) -> u32;
fn len(&self) -> u32;
Expand Down
6 changes: 2 additions & 4 deletions crates/base/src/worker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,18 @@ pub trait WorkerOperations {
}

pub trait ViewBasicOperations {
fn basic<'a, F: Fn(Pointer) -> bool + Clone + 'a>(
fn basic<'a>(
&'a self,
vector: &'a OwnedVector,
opts: &'a SearchOptions,
filter: F,
) -> Result<Box<dyn Iterator<Item = Pointer> + 'a>, BasicError>;
}

pub trait ViewVbaseOperations {
fn vbase<'a, F: FnMut(Pointer) -> bool + Clone + 'a>(
fn vbase<'a>(
&'a self,
vector: &'a OwnedVector,
opts: &'a SearchOptions,
filter: F,
) -> Result<Box<dyn Iterator<Item = Pointer> + 'a>, VbaseError>;
}

Expand Down
16 changes: 4 additions & 12 deletions crates/flat/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,16 @@ impl<O: OperatorFlat> Flat<O> {
&self,
vector: Borrowed<'_, O>,
_opts: &SearchOptions,
filter: impl Filter,
) -> BinaryHeap<Reverse<Element>> {
basic(&self.mmap, vector, filter)
basic(&self.mmap, vector)
}

pub fn vbase<'a>(
&'a self,
vector: Borrowed<'a, O>,
_opts: &'a SearchOptions,
filter: impl Filter + 'a,
) -> (Vec<Element>, Box<(dyn Iterator<Item = Element> + 'a)>) {
vbase(&self.mmap, vector, filter)
vbase(&self.mmap, vector)
}

pub fn len(&self) -> u32 {
Expand Down Expand Up @@ -129,31 +127,25 @@ pub fn open<O: OperatorFlat>(path: &Path, options: IndexOptions) -> FlatMmap<O>
pub fn basic<O: OperatorFlat>(
mmap: &FlatMmap<O>,
vector: Borrowed<'_, O>,
mut filter: impl Filter,
) -> BinaryHeap<Reverse<Element>> {
let mut result = BinaryHeap::new();
for i in 0..mmap.storage.len() {
let distance = mmap.quantization.distance(vector, i);
let payload = mmap.storage.payload(i);
if filter.check(payload) {
result.push(Reverse(Element { distance, payload }));
}
result.push(Reverse(Element { distance, payload }));
}
result
}

pub fn vbase<'a, O: OperatorFlat>(
mmap: &'a FlatMmap<O>,
vector: Borrowed<'a, O>,
mut filter: impl Filter + 'a,
) -> (Vec<Element>, Box<dyn Iterator<Item = Element> + 'a>) {
let mut result = Vec::new();
for i in 0..mmap.storage.len() {
let distance = mmap.quantization.distance(vector, i);
let payload = mmap.storage.payload(i);
if filter.check(payload) {
result.push(Element { distance, payload });
}
result.push(Element { distance, payload });
}
(result, Box::new(std::iter::empty()))
}
3 changes: 0 additions & 3 deletions crates/hnsw/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@ name = "hnsw"
version.workspace = true
edition.workspace = true

[features]
stand-alone-test = []

[dependencies]
bytemuck.workspace = true
parking_lot.workspace = true
Expand Down
Loading

0 comments on commit 4360cac

Please sign in to comment.