From cbb8e483929c5f2c49ae11bbe16d2019516ab11f Mon Sep 17 00:00:00 2001 From: Andrey Tkachenko Date: Mon, 4 Apr 2022 20:00:00 +0400 Subject: [PATCH] Add collection info, creation, deletion, points insertion --- .gitignore | 1 + Cargo.lock | 1064 ++++++++++++++++++++++++++++++++++++++ Cargo.toml | 16 + examples/get_info.rs | 65 +++ src/error.rs | 10 + src/lib.rs | 146 ++++++ src/models/collection.rs | 982 +++++++++++++++++++++++++++++++++++ src/models/mod.rs | 3 + 8 files changed, 2287 insertions(+) create mode 100644 .gitignore create mode 100644 Cargo.lock create mode 100644 Cargo.toml create mode 100644 examples/get_info.rs create mode 100644 src/error.rs create mode 100644 src/lib.rs create mode 100644 src/models/collection.rs create mode 100644 src/models/mod.rs diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c41cc9e --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/target \ No newline at end of file diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 0000000..75e2c92 --- /dev/null +++ b/Cargo.lock @@ -0,0 +1,1064 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "autocfg" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" + +[[package]] +name = "base64" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "904dfeac50f3cdaba28fc6f57fdcddb75f49ed61346676a78c4ffe55877802fd" + +[[package]] +name = "bitflags" +version = "1.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" + +[[package]] +name = "bumpalo" +version = "3.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4a45a46ab1f2412e53d3a0ade76ffad2025804294569aae387231a0cd6e0899" + +[[package]] +name = "bytes" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c4872d67bab6358e59559027aa3b9157c53d9358c51423c17554809a8858e0f8" + +[[package]] +name = "cc" +version = "1.0.73" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2fff2a6927b3bb87f9595d67196a70493f627687a71d87a0d692242c33f58c11" + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "core-foundation" +version = "0.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "194a7a9e6de53fa55116934067c844d9d749312f75c6f6d0980e8c252f8c2146" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "core-foundation-sys" +version = "0.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5827cebf4670468b8772dd191856768aedcb1b0278a04f989f7766351917b9dc" + +[[package]] +name = "encoding_rs" +version = "0.8.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7896dc8abb250ffdda33912550faa54c88ec8b998dec0b2c55ab224921ce11df" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "fastrand" +version = "1.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3fcf0cee53519c866c09b5de1f6c56ff9d647101f81c1964fa632e148896cdf" +dependencies = [ + "instant", +] + +[[package]] +name = "fnv" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" + +[[package]] +name = "foreign-types" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" +dependencies = [ + "foreign-types-shared", +] + +[[package]] +name = "foreign-types-shared" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" + +[[package]] +name = "form_urlencoded" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5fc25a87fa4fd2094bffb06925852034d90a17f0d1e05197d4956d3555752191" +dependencies = [ + "matches", + "percent-encoding", +] + +[[package]] +name = "futures-channel" +version = "0.3.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3083ce4b914124575708913bca19bfe887522d6e2e6d0952943f5eac4a74010" +dependencies = [ + "futures-core", +] + +[[package]] +name = "futures-core" +version = "0.3.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c09fd04b7e4073ac7156a9539b57a484a8ea920f79c7c675d05d289ab6110d3" + +[[package]] +name = "futures-sink" +version = "0.3.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "21163e139fa306126e6eedaf49ecdb4588f939600f0b1e770f4205ee4b7fa868" + +[[package]] +name = "futures-task" +version = "0.3.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "57c66a976bf5909d801bbef33416c41372779507e7a6b3a5e25e4749c58f776a" + +[[package]] +name = "futures-util" +version = "0.3.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d8b7abd5d659d9b90c8cba917f6ec750a74e2dc23902ef9cd4cc8c8b22e6036a" +dependencies = [ + "futures-core", + "futures-task", + "pin-project-lite", + "pin-utils", +] + +[[package]] +name = "h2" +version = "0.3.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "37a82c6d637fc9515a4694bbf1cb2457b79d81ce52b3108bdeea58b07dd34a57" +dependencies = [ + "bytes", + "fnv", + "futures-core", + "futures-sink", + "futures-util", + "http", + "indexmap", + "slab", + "tokio", + "tokio-util", + "tracing", +] + +[[package]] +name = "hashbrown" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ab5ef0d4909ef3724cc8cce6ccc8572c5c817592e9285f5464f8e86f8bd3726e" + +[[package]] +name = "hermit-abi" +version = "0.1.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33" +dependencies = [ + "libc", +] + +[[package]] +name = "http" +version = "0.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "31f4c6746584866f0feabcc69893c5b51beef3831656a968ed7ae254cdc4fd03" +dependencies = [ + "bytes", + "fnv", + "itoa", +] + +[[package]] +name = "http-body" +version = "0.4.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1ff4f84919677303da5f147645dbea6b1881f368d03ac84e1dc09031ebd7b2c6" +dependencies = [ + "bytes", + "http", + "pin-project-lite", +] + +[[package]] +name = "httparse" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9100414882e15fb7feccb4897e5f0ff0ff1ca7d1a86a23208ada4d7a18e6c6c4" + +[[package]] +name = "httpdate" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c4a1e36c821dbe04574f602848a19f742f4fb3c98d40449f11bcad18d6b17421" + +[[package]] +name = "hyper" +version = "0.14.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b26ae0a80afebe130861d90abf98e3814a4f28a4c6ffeb5ab8ebb2be311e0ef2" +dependencies = [ + "bytes", + "futures-channel", + "futures-core", + "futures-util", + "h2", + "http", + "http-body", + "httparse", + "httpdate", + "itoa", + "pin-project-lite", + "socket2", + "tokio", + "tower-service", + "tracing", + "want", +] + +[[package]] +name = "hyper-tls" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d6183ddfa99b85da61a140bea0efc93fdf56ceaa041b37d553518030827f9905" +dependencies = [ + "bytes", + "hyper", + "native-tls", + "tokio", + "tokio-native-tls", +] + +[[package]] +name = "idna" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "418a0a6fab821475f634efe3ccc45c013f742efe03d853e8d3355d5cb850ecf8" +dependencies = [ + "matches", + "unicode-bidi", + "unicode-normalization", +] + +[[package]] +name = "indexmap" +version = "1.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0f647032dfaa1f8b6dc29bd3edb7bbef4861b8b8007ebb118d6db284fd59f6ee" +dependencies = [ + "autocfg", + "hashbrown", +] + +[[package]] +name = "instant" +version = "0.1.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a5bbe824c507c5da5956355e86a746d82e0e1464f65d862cc5e71da70e94b2c" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "ipnet" +version = "2.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "35e70ee094dc02fd9c13fdad4940090f22dbd6ac7c9e7094a46cf0232a50bc7c" + +[[package]] +name = "itoa" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1aab8fc367588b89dcee83ab0fd66b72b50b72fa1904d7095045ace2b0c81c35" + +[[package]] +name = "js-sys" +version = "0.3.56" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a38fc24e30fd564ce974c02bf1d337caddff65be6cc4735a1f7eab22a7440f04" +dependencies = [ + "wasm-bindgen", +] + +[[package]] +name = "lazy_static" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" + +[[package]] +name = "libc" +version = "0.2.121" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "efaa7b300f3b5fe8eb6bf21ce3895e1751d9665086af2d64b42f19701015ff4f" + +[[package]] +name = "lock_api" +version = "0.4.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "327fa5b6a6940e4699ec49a9beae1ea4845c6bab9314e4f84ac68742139d8c53" +dependencies = [ + "autocfg", + "scopeguard", +] + +[[package]] +name = "log" +version = "0.4.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6389c490849ff5bc16be905ae24bc913a9c8892e19b2341dbc175e14c341c2b8" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "matches" +version = "0.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a3e378b66a060d48947b590737b30a1be76706c8dd7b8ba0f2fe3989c68a853f" + +[[package]] +name = "memchr" +version = "2.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "308cc39be01b73d0d18f82a0e7b2a3df85245f84af96fdddc5d202d27e47b86a" + +[[package]] +name = "mime" +version = "0.3.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2a60c7ce501c71e03a9c9c0d35b861413ae925bd979cc7a4e30d060069aaac8d" + +[[package]] +name = "mio" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "52da4364ffb0e4fe33a9841a98a3f3014fb964045ce4f7a45a398243c8d6b0c9" +dependencies = [ + "libc", + "log", + "miow", + "ntapi", + "wasi", + "winapi", +] + +[[package]] +name = "miow" +version = "0.3.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b9f1c5b025cda876f66ef43a113f91ebc9f4ccef34843000e0adf6ebbab84e21" +dependencies = [ + "winapi", +] + +[[package]] +name = "native-tls" +version = "0.2.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fd7e2f3618557f980e0b17e8856252eee3c97fa12c54dff0ca290fb6266ca4a9" +dependencies = [ + "lazy_static", + "libc", + "log", + "openssl", + "openssl-probe", + "openssl-sys", + "schannel", + "security-framework", + "security-framework-sys", + "tempfile", +] + +[[package]] +name = "ntapi" +version = "0.3.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c28774a7fd2fbb4f0babd8237ce554b73af68021b5f695a3cebd6c59bac0980f" +dependencies = [ + "winapi", +] + +[[package]] +name = "num_cpus" +version = "1.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "19e64526ebdee182341572e50e9ad03965aa510cd94427a4549448f285e957a1" +dependencies = [ + "hermit-abi", + "libc", +] + +[[package]] +name = "once_cell" +version = "1.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87f3e037eac156d1775da914196f0f37741a274155e34a0b7e427c35d2a2ecb9" + +[[package]] +name = "openssl" +version = "0.10.38" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c7ae222234c30df141154f159066c5093ff73b63204dcda7121eb082fc56a95" +dependencies = [ + "bitflags", + "cfg-if", + "foreign-types", + "libc", + "once_cell", + "openssl-sys", +] + +[[package]] +name = "openssl-probe" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" + +[[package]] +name = "openssl-sys" +version = "0.9.72" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7e46109c383602735fa0a2e48dd2b7c892b048e1bf69e5c3b1d804b7d9c203cb" +dependencies = [ + "autocfg", + "cc", + "libc", + "pkg-config", + "vcpkg", +] + +[[package]] +name = "parking_lot" +version = "0.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87f5ec2493a61ac0506c0f4199f99070cbe83857b0337006a30f3e6719b8ef58" +dependencies = [ + "lock_api", + "parking_lot_core", +] + +[[package]] +name = "parking_lot_core" +version = "0.9.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "995f667a6c822200b0433ac218e05582f0e2efa1b922a3fd2fbaadc5f87bab37" +dependencies = [ + "cfg-if", + "libc", + "redox_syscall", + "smallvec", + "windows-sys", +] + +[[package]] +name = "percent-encoding" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d4fd5641d01c8f18a23da7b6fe29298ff4b55afcccdf78973b24cf3175fee32e" + +[[package]] +name = "pin-project-lite" +version = "0.2.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e280fbe77cc62c91527259e9442153f4688736748d24660126286329742b4c6c" + +[[package]] +name = "pin-utils" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" + +[[package]] +name = "pkg-config" +version = "0.3.25" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1df8c4ec4b0627e53bdf214615ad287367e482558cf84b109250b37464dc03ae" + +[[package]] +name = "proc-macro2" +version = "1.0.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c7342d5883fbccae1cc37a2353b09c87c9b0f3afd73f5fb9bba687a1f733b029" +dependencies = [ + "unicode-xid", +] + +[[package]] +name = "qdrant_rust_client" +version = "0.1.0" +dependencies = [ + "reqwest", + "serde", + "serde_derive", + "serde_json", + "thiserror", + "tokio", +] + +[[package]] +name = "quote" +version = "1.0.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "632d02bff7f874a36f33ea8bb416cd484b90cc66c1194b1a1110d067a7013f58" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "redox_syscall" +version = "0.2.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "62f25bc4c7e55e0b0b7a1d43fb893f4fa1361d0abe38b9ce4f323c2adfe6ef42" +dependencies = [ + "bitflags", +] + +[[package]] +name = "remove_dir_all" +version = "0.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3acd125665422973a33ac9d3dd2df85edad0f4ae9b00dafb1a05e43a9f5ef8e7" +dependencies = [ + "winapi", +] + +[[package]] +name = "reqwest" +version = "0.11.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "46a1f7aa4f35e5e8b4160449f51afc758f0ce6454315a9fa7d0d113e958c41eb" +dependencies = [ + "base64", + "bytes", + "encoding_rs", + "futures-core", + "futures-util", + "h2", + "http", + "http-body", + "hyper", + "hyper-tls", + "ipnet", + "js-sys", + "lazy_static", + "log", + "mime", + "native-tls", + "percent-encoding", + "pin-project-lite", + "serde", + "serde_json", + "serde_urlencoded", + "tokio", + "tokio-native-tls", + "url", + "wasm-bindgen", + "wasm-bindgen-futures", + "web-sys", + "winreg", +] + +[[package]] +name = "ryu" +version = "1.0.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "73b4b750c782965c211b42f022f59af1fbceabdd026623714f104152f1ec149f" + +[[package]] +name = "schannel" +version = "0.1.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f05ba609c234e60bee0d547fe94a4c7e9da733d1c962cf6e59efa4cd9c8bc75" +dependencies = [ + "lazy_static", + "winapi", +] + +[[package]] +name = "scopeguard" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" + +[[package]] +name = "security-framework" +version = "2.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2dc14f172faf8a0194a3aded622712b0de276821addc574fa54fc0a1167e10dc" +dependencies = [ + "bitflags", + "core-foundation", + "core-foundation-sys", + "libc", + "security-framework-sys", +] + +[[package]] +name = "security-framework-sys" +version = "2.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0160a13a177a45bfb43ce71c01580998474f556ad854dcbca936dd2841a5c556" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "serde" +version = "1.0.136" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce31e24b01e1e524df96f1c2fdd054405f8d7376249a5110886fb4b658484789" + +[[package]] +name = "serde_derive" +version = "1.0.136" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08597e7152fcd306f41838ed3e37be9eaeed2b61c42e2117266a554fab4662f9" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "serde_json" +version = "1.0.79" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e8d9fa5c3b304765ce1fd9c4c8a3de2c8db365a5b91be52f186efc675681d95" +dependencies = [ + "itoa", + "ryu", + "serde", +] + +[[package]] +name = "serde_urlencoded" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3491c14715ca2294c4d6a88f15e84739788c1d030eed8c110436aafdaa2f3fd" +dependencies = [ + "form_urlencoded", + "itoa", + "ryu", + "serde", +] + +[[package]] +name = "signal-hook-registry" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e51e73328dc4ac0c7ccbda3a494dfa03df1de2f46018127f60c693f2648455b0" +dependencies = [ + "libc", +] + +[[package]] +name = "slab" +version = "0.4.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9def91fd1e018fe007022791f865d0ccc9b3a0d5001e01aabb8b40e46000afb5" + +[[package]] +name = "smallvec" +version = "1.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f2dd574626839106c320a323308629dcb1acfc96e32a8cba364ddc61ac23ee83" + +[[package]] +name = "socket2" +version = "0.4.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "66d72b759436ae32898a2af0a14218dbf55efde3feeb170eb623637db85ee1e0" +dependencies = [ + "libc", + "winapi", +] + +[[package]] +name = "syn" +version = "1.0.90" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "704df27628939572cd88d33f171cd6f896f4eaca85252c6e0a72d8d8287ee86f" +dependencies = [ + "proc-macro2", + "quote", + "unicode-xid", +] + +[[package]] +name = "tempfile" +version = "3.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5cdb1ef4eaeeaddc8fbd371e5017057064af0911902ef36b39801f67cc6d79e4" +dependencies = [ + "cfg-if", + "fastrand", + "libc", + "redox_syscall", + "remove_dir_all", + "winapi", +] + +[[package]] +name = "thiserror" +version = "1.0.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "854babe52e4df1653706b98fcfc05843010039b406875930a70e4d9644e5c417" +dependencies = [ + "thiserror-impl", +] + +[[package]] +name = "thiserror-impl" +version = "1.0.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aa32fd3f627f367fe16f893e2597ae3c05020f8bba2666a4e6ea73d377e5714b" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "tinyvec" +version = "1.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2c1c1d5a42b6245520c249549ec267180beaffcc0615401ac8e31853d4b6d8d2" +dependencies = [ + "tinyvec_macros", +] + +[[package]] +name = "tinyvec_macros" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cda74da7e1a664f795bb1f8a87ec406fb89a02522cf6e50620d016add6dbbf5c" + +[[package]] +name = "tokio" +version = "1.17.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2af73ac49756f3f7c01172e34a23e5d0216f6c32333757c2c61feb2bbff5a5ee" +dependencies = [ + "bytes", + "libc", + "memchr", + "mio", + "num_cpus", + "once_cell", + "parking_lot", + "pin-project-lite", + "signal-hook-registry", + "socket2", + "tokio-macros", + "winapi", +] + +[[package]] +name = "tokio-macros" +version = "1.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b557f72f448c511a979e2564e55d74e6c4432fc96ff4f6241bc6bded342643b7" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "tokio-native-tls" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f7d995660bd2b7f8c1568414c1126076c13fbb725c40112dc0120b78eb9b717b" +dependencies = [ + "native-tls", + "tokio", +] + +[[package]] +name = "tokio-util" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0edfdeb067411dba2044da6d1cb2df793dd35add7888d73c16e3381ded401764" +dependencies = [ + "bytes", + "futures-core", + "futures-sink", + "pin-project-lite", + "tokio", + "tracing", +] + +[[package]] +name = "tower-service" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "360dfd1d6d30e05fda32ace2c8c70e9c0a9da713275777f5a4dbb8a1893930c6" + +[[package]] +name = "tracing" +version = "0.1.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4a1bdf54a7c28a2bbf701e1d2233f6c77f473486b94bee4f9678da5a148dca7f" +dependencies = [ + "cfg-if", + "pin-project-lite", + "tracing-attributes", + "tracing-core", +] + +[[package]] +name = "tracing-attributes" +version = "0.1.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2e65ce065b4b5c53e73bb28912318cb8c9e9ad3921f1d669eb0e68b4c8143a2b" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "tracing-core" +version = "0.1.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aa31669fa42c09c34d94d8165dd2012e8ff3c66aca50f3bb226b68f216f2706c" +dependencies = [ + "lazy_static", +] + +[[package]] +name = "try-lock" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "59547bce71d9c38b83d9c0e92b6066c4253371f15005def0c30d9657f50c7642" + +[[package]] +name = "unicode-bidi" +version = "0.3.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1a01404663e3db436ed2746d9fefef640d868edae3cceb81c3b8d5732fda678f" + +[[package]] +name = "unicode-normalization" +version = "0.1.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d54590932941a9e9266f0832deed84ebe1bf2e4c9e4a3554d393d18f5e854bf9" +dependencies = [ + "tinyvec", +] + +[[package]] +name = "unicode-xid" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ccb82d61f80a663efe1f787a51b16b5a51e3314d6ac365b08639f52387b33f3" + +[[package]] +name = "url" +version = "2.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a507c383b2d33b5fc35d1861e77e6b383d158b2da5e14fe51b83dfedf6fd578c" +dependencies = [ + "form_urlencoded", + "idna", + "matches", + "percent-encoding", +] + +[[package]] +name = "vcpkg" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" + +[[package]] +name = "want" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1ce8a968cb1cd110d136ff8b819a556d6fb6d919363c61534f6860c7eb172ba0" +dependencies = [ + "log", + "try-lock", +] + +[[package]] +name = "wasi" +version = "0.11.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" + +[[package]] +name = "wasm-bindgen" +version = "0.2.79" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "25f1af7423d8588a3d840681122e72e6a24ddbcb3f0ec385cac0d12d24256c06" +dependencies = [ + "cfg-if", + "wasm-bindgen-macro", +] + +[[package]] +name = "wasm-bindgen-backend" +version = "0.2.79" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b21c0df030f5a177f3cba22e9bc4322695ec43e7257d865302900290bcdedca" +dependencies = [ + "bumpalo", + "lazy_static", + "log", + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-futures" +version = "0.4.29" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2eb6ec270a31b1d3c7e266b999739109abce8b6c87e4b31fcfcd788b65267395" +dependencies = [ + "cfg-if", + "js-sys", + "wasm-bindgen", + "web-sys", +] + +[[package]] +name = "wasm-bindgen-macro" +version = "0.2.79" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2f4203d69e40a52ee523b2529a773d5ffc1dc0071801c87b3d270b471b80ed01" +dependencies = [ + "quote", + "wasm-bindgen-macro-support", +] + +[[package]] +name = "wasm-bindgen-macro-support" +version = "0.2.79" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bfa8a30d46208db204854cadbb5d4baf5fcf8071ba5bf48190c3e59937962ebc" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-backend", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-shared" +version = "0.2.79" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3d958d035c4438e28c70e4321a2911302f10135ce78a9c7834c0cab4123d06a2" + +[[package]] +name = "web-sys" +version = "0.3.56" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c060b319f29dd25724f09a2ba1418f142f539b2be99fbf4d2d5a8f7330afb8eb" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + +[[package]] +name = "winapi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" +dependencies = [ + "winapi-i686-pc-windows-gnu", + "winapi-x86_64-pc-windows-gnu", +] + +[[package]] +name = "winapi-i686-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" + +[[package]] +name = "winapi-x86_64-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" + +[[package]] +name = "windows-sys" +version = "0.34.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5acdd78cb4ba54c0045ac14f62d8f94a03d10047904ae2a40afa1e99d8f70825" +dependencies = [ + "windows_aarch64_msvc", + "windows_i686_gnu", + "windows_i686_msvc", + "windows_x86_64_gnu", + "windows_x86_64_msvc", +] + +[[package]] +name = "windows_aarch64_msvc" +version = "0.34.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "17cffbe740121affb56fad0fc0e421804adf0ae00891205213b5cecd30db881d" + +[[package]] +name = "windows_i686_gnu" +version = "0.34.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2564fde759adb79129d9b4f54be42b32c89970c18ebf93124ca8870a498688ed" + +[[package]] +name = "windows_i686_msvc" +version = "0.34.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9cd9d32ba70453522332c14d38814bceeb747d80b3958676007acadd7e166956" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.34.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cfce6deae227ee8d356d19effc141a509cc503dfd1f850622ec4b0f84428e1f4" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.34.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d19538ccc21819d01deaf88d6a17eae6596a12e9aafdbb97916fb49896d89de9" + +[[package]] +name = "winreg" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "80d0f4e272c85def139476380b12f9ac60926689dd2e01d4923222f40580869d" +dependencies = [ + "winapi", +] diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..ba06bc5 --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,16 @@ +[package] +name = "qdrant_rust_client" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +serde = "1.0.136" +serde_derive = "1.0.136" +serde_json = "1.0.79" +thiserror = "1.0.30" +reqwest = { version = "0.11.10", features = ["json", "serde_json"] } + +[dev-dependencies] +tokio = { version = "1.17.0", features = ["full"] } diff --git a/examples/get_info.rs b/examples/get_info.rs new file mode 100644 index 0000000..8d62839 --- /dev/null +++ b/examples/get_info.rs @@ -0,0 +1,65 @@ +use qdrant_rust_client::{ + models::{CollectionsResponse, Distance, InlineResponse, PointStruct}, + Client, +}; + +#[tokio::main] +async fn main() { + let client = Client::new("localhost", 6333, "http"); + let coll = "test_collection"; + let res = client + .create_collection(coll, 8, Distance::Cosine) + .await + .unwrap(); + + let points = vec![ + PointStruct { + id: 1.into(), + payload: None, + vector: vec![1.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0], + }, + PointStruct { + id: 2.into(), + payload: None, + vector: vec![1.0, 1.0, 2.0, 4.0, 4.0, 5.0, 6.0, 8.0], + }, + PointStruct { + id: 3.into(), + payload: None, + vector: vec![0.0, 1.0, 3.0, 3.0, 4.0, 5.0, 6.0, 8.0], + }, + PointStruct { + id: 4.into(), + payload: None, + vector: vec![0.0, 1.0, 4.0, 3.0, 4.0, 5.0, 6.0, 7.0], + }, + PointStruct { + id: 5.into(), + payload: None, + vector: vec![1.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0], + }, + PointStruct { + id: 6.into(), + payload: None, + vector: vec![0.0, 2.0, 2.0, 4.0, 4.0, 5.0, 6.0, 7.0], + }, + PointStruct { + id: 7.into(), + payload: None, + vector: vec![1.0, 3.0, 2.0, 4.0, 5.0, 5.0, 7.0, 7.0], + }, + PointStruct { + id: 8.into(), + payload: None, + vector: vec![0.0, 4.0, 2.0, 3.0, 5.0, 5.0, 7.0, 7.0], + }, + ]; + + let resp = client.collection_add_points(coll, points).await.unwrap(); + println!("{:#?}", resp); + + let info = client.get_collection_info(coll).await.unwrap(); + let res = client.delete_collection(coll).await.unwrap(); + + println!("{:#?}", info); +} diff --git a/src/error.rs b/src/error.rs new file mode 100644 index 0000000..da0154f --- /dev/null +++ b/src/error.rs @@ -0,0 +1,10 @@ +use thiserror::Error; + +#[derive(Debug, Error)] +pub enum Error { + #[error("Reqwest Error: {0}")] + Reqwest(#[from] reqwest::Error), + + #[error("{0}")] + QDrantError(String), +} diff --git a/src/lib.rs b/src/lib.rs new file mode 100644 index 0000000..ba3b0d0 --- /dev/null +++ b/src/lib.rs @@ -0,0 +1,146 @@ +use std::borrow::Cow; + +use error::Error; +use models::{ + CollectionInfo, CollectionParams, Distance, Filter, InlineResponseResult, InlineResponseStatus, + PointStruct, PointsList, UpdateResult, +}; + +use crate::models::InlineResponse; + +pub mod error; +pub mod models; + +pub struct Client { + host: Cow<'static, str>, + port: u16, + schema: Cow<'static, str>, +} + +impl Client { + pub fn new>, S: Into>>( + host: H, + port: u16, + schema: S, + ) -> Self { + Self { + host: host.into(), + port, + schema: schema.into(), + } + } + + pub async fn get_collection_info(&self, collection: &str) -> Result { + let url = self.build_url(collection, ""); + let res = reqwest::get(&url).await?; + let res: InlineResponse = res.json().await?; + + match res.status { + InlineResponseStatus::Error(err) => { + Err(Error::QDrantError(err.error.unwrap_or(String::from("")))) + } + InlineResponseStatus::Ok(_) => match res.result { + Some(inner) => match inner { + InlineResponseResult::CollectionInfo(info) => Ok(info), + _ => unreachable!(), + }, + None => unimplemented!(), + }, + } + } + + pub async fn create_collection( + &self, + collection: &str, + vector_size: i64, + distance: Distance, + ) -> Result { + let req = CollectionParams { + vector_size, + distance, + }; + + let url = self.build_url(collection, ""); + let client = reqwest::Client::new(); + + let res: InlineResponse = client.put(&url).json(&req).send().await?.json().await?; + + match res.status { + InlineResponseStatus::Error(err) => { + Err(Error::QDrantError(err.error.unwrap_or(String::from("")))) + } + InlineResponseStatus::Ok(_) => match res.result { + Some(inner) => match inner { + InlineResponseResult::Bool(resp) => Ok(resp), + _ => unreachable!(), + }, + None => unimplemented!(), + }, + } + } + + pub async fn delete_collection(&self, collection: &str) -> Result { + let url = self.build_url(collection, ""); + let client = reqwest::Client::new(); + + let res: InlineResponse = client.delete(&url).send().await?.json().await?; + + match res.status { + InlineResponseStatus::Error(err) => { + Err(Error::QDrantError(err.error.unwrap_or(String::from("")))) + } + InlineResponseStatus::Ok(_) => match res.result { + Some(inner) => match inner { + InlineResponseResult::Bool(resp) => Ok(resp), + _ => unreachable!(), + }, + None => unimplemented!(), + }, + } + } + + pub async fn collection_add_points( + &self, + collection: &str, + points: Vec, + ) -> Result { + let req = PointsList { points }; + + let url = self.build_url(collection, "/points?wait=true"); + let client = reqwest::Client::new(); + let res: InlineResponse = client.put(&url).json(&req).send().await?.json().await?; + + match res.status { + InlineResponseStatus::Error(err) => { + Err(Error::QDrantError(err.error.unwrap_or(String::from("")))) + } + InlineResponseStatus::Ok(_) => match res.result { + Some(inner) => match inner { + InlineResponseResult::UpdateResult(resp) => Ok(resp), + _ => unreachable!(), + }, + None => unimplemented!(), + }, + } + } + + pub async fn collection_search_points( + &self, + vector: Vec, + top: u64, + filter: Option, + ) -> Result<(), Error> { + Ok(()) + } + + // pub async fn collection_add_points_batch(&self, batch_ids: &[], batch_vectors: &[Vec<64>], batch_payloads: Option<>) -> Result<(), Error> { + + // } + + fn build_url(&self, collection: &str, post: &str) -> String { + format!( + "{}://{}:{}/collections/{collection}{post}", + self.schema, self.host, self.port + ) + } +} diff --git a/src/models/collection.rs b/src/models/collection.rs new file mode 100644 index 0000000..43c9d83 --- /dev/null +++ b/src/models/collection.rs @@ -0,0 +1,982 @@ +use serde_derive::{Deserialize, Serialize}; +use serde_json::Value; +use std::collections::HashMap; + +#[derive(Debug, Clone, Deserialize)] +pub enum OkStatus { + #[serde(rename = "ok")] + Ok, +} + +#[derive(Debug, Clone, Deserialize)] +pub enum CollectionStatus { + #[serde(rename = "green")] + Green, + + #[serde(rename = "yellow")] + Yellow, + + #[serde(rename = "red")] + Red, +} + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub enum Distance { + Cosine, + Euclid, + Dot, +} + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub enum Match { + MatchKeyword(MatchKeyword), + MatchInteger(MatchInteger), +} + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub enum AliasOperations { + CreateAliasOperation(CreateAliasOperation), + DeleteAliasOperation(DeleteAliasOperation), + RenameAliasOperation(RenameAliasOperation), +} + +#[derive(Debug, Clone, Serialize, Deserialize)] +#[serde(untagged)] +pub enum ExtendedPointId { + Integer(i64), + String(String), +} + +impl From for ExtendedPointId { + fn from(val: i64) -> Self { + Self::Integer(val) + } +} + +impl From for ExtendedPointId { + fn from(val: String) -> Self { + Self::String(val) + } +} + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub enum PointsSelector { + PointIdsList(PointIdsList), + FilterSelector(FilterSelector), +} + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub enum PayloadSelector { + PayloadSelectorInclude(PayloadSelectorInclude), + PayloadSelectorExclude(PayloadSelectorExclude), +} + +#[derive(Debug, Clone, Deserialize)] +pub enum WithPayloadInterface { + PayloadSelector(PayloadSelector), + StringList(Vec), + Bool(bool), +} + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub enum Condition { + FieldCondition(FieldCondition), + HasIdCondition(HasIdCondition), + Filter(Filter), +} + +#[derive(Debug, Clone, Deserialize)] +#[serde(untagged)] +pub enum PointInsertOperations { + PointsBatch(PointsBatch), + PointsList(PointsList), +} + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct Batch { + pub ids: Vec, + pub payloads: Option>>, + pub vectors: Vec>, +} + +/// +/// Operation for performing changes of collection aliases. Alias changes are atomic, meaning +/// that no collection modifications can happen between alias operations. +/// +#[derive(Debug, Clone, Deserialize)] +pub struct ChangeAliasesOperation { + /// Operation for performing changes of collection aliases. Alias changes are atomic, meaning + /// that no collection modifications can happen between alias operations. + pub actions: Vec, +} + +#[derive(Debug, Clone, Deserialize)] +pub enum UpdateStatus { + /// acknowledged + #[serde(rename = "acknowledged")] + Acknowledged, + + // completed + #[serde(rename = "completed")] + Completed, +} + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct CollectionParams { + /// Size of a vectors used + pub vector_size: i64, + pub distance: Distance, +} + +#[derive(Debug, Clone, Deserialize)] +pub struct WalConfig { + /// + /// Size of a single WAL segment in MB + /// + wal_capacity_mb: i64, + + /// + /// Number of WAL segments to create ahead of actually used ones + /// + wal_segments_ahead: i64, +} + +#[derive(Debug, Clone, Deserialize)] +pub struct WalConfigDiff { + /// + /// Size of a single WAL segment in MB + wal_capacity_mb: Option, + + /// + /// Number of WAL segments to create ahead of actually used ones + wal_segments_ahead: Option, +} + +#[derive(Debug, Clone, Deserialize)] +pub struct CollectionDescription { + name: String, +} + +#[derive(Debug, Clone, Deserialize)] +pub struct CollectionsResponse { + collections: Vec, +} + +#[derive(Debug, Clone, Deserialize)] +pub struct CollectionConfig { + hnsw_config: HnswConfig, + params: CollectionParams, + optimizer_config: OptimizersConfig, + wal_config: WalConfig, +} + +/// +/// Current statistics and configuration of the collection +/// +#[derive(Debug, Clone, Deserialize)] +pub struct CollectionInfo { + /// + /// Current statistics and configuration of the collection + status: CollectionStatus, + + /// + /// Current statistics and configuration of the collection + optimizer_status: OptimizersStatus, + + /// + /// Number of vectors in collection + vectors_count: i64, + + /// + /// Number of segments in collection + segments_count: i64, + + /// + /// Disk space, used by collection + disk_data_size: i64, + + /// + /// RAM used by collection + ram_data_size: i64, + + /// + /// Current statistics and configuration of the collection + config: CollectionConfig, + + /// + /// Types of stored payload + payload_schema: HashMap, +} + +/// +/// Create alternative name for a collection. Collection will be available under both names for +/// search, retrieve, +/// +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct CreateAlias { + /// Create alternative name for a collection. Collection will be available under both names for + /// search, retrieve, + alias_name: String, + + /// Create alternative name for a collection. Collection will be available under both names for + /// search, retrieve, + collection_name: String, +} + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct CreateAliasOperation { + create_alias: CreateAlias, +} + +/// +/// Operation for creating new collection and (optionally) specify index params +/// +#[derive(Debug, Clone, Deserialize)] +pub struct CreateCollection { + /// Operation for creating new collection and (optionally) specify index params + pub distance: Distance, + + /// Custom params for HNSW index. If none - values from service configuration file are used. + pub hnsw_config: Option, + + /// Custom params for Optimizers. If none - values from service configuration file are used. + pub optimizers_config: Option, + + /// Operation for creating new collection and (optionally) specify index params + pub vector_size: i64, + + /// Custom params for WAL. If none - values from service configuration file are used. + pub wal_config: Option, +} + +/// +/// Operation for creating new collection and (optionally) specify index params +/// +#[derive(Debug, Clone, Deserialize)] +pub struct CreateCollectionOperation { + /// Operation for creating new collection and (optionally) specify index params + pub collection_name: String, + + /// Operation for creating new collection and (optionally) specify index params + pub distance: Distance, + + /// Custom params for HNSW index. If none - values from service configuration file are used. + pub hnsw_config: Option, + + /// Custom params for Optimizers. If none - values from service configuration file are used. + pub optimizers_config: Option, + + /// Operation for creating new collection and (optionally) specify index params + pub vector_size: i64, + + /// Custom params for WAL. If none - values from service configuration file are used. + pub wal_config: Option, +} + +#[derive(Debug, Clone, Deserialize)] +pub struct CreateFieldIndex { + field_name: String, +} + +/// +/// Delete alias if exists +/// +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct DeleteAlias { + /// Delete alias if exists + alias_name: String, +} +/// +/// Delete alias if exists +/// +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct DeleteAliasOperation { + /// Delete alias if exists + delete_alias: DeleteAlias, +} + +#[derive(Debug, Clone, Deserialize)] +pub struct DeletePayload { + keys: Vec, + points: Vec, +} + +/// +/// All possible payload filtering conditions +/// +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct FieldCondition { + /// All possible payload filtering conditions + key: String, + + /// Check if points geo location lies in a given area + geo_bounding_box: Option, + + /// Check if geo point is within a given radius + geo_radius: Option, + + /// Check if point has field with a given value + #[serde(rename = "match")] + _match: Option, + + /// Check if points value lies in a given range + range: Option, +} + +/// +/// Create index for payload field +/// +#[derive(Debug, Clone, Deserialize)] +pub struct FieldIndexOperationsOneOf { + /// Create index for payload field + create_index: String, +} + +/// +/// Delete index for the field +/// +#[derive(Debug, Clone, Deserialize)] +pub struct FieldIndexOperationsOneOf1 { + /// Delete index for the field + delete_index: String, +} + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct Filter { + /// All conditions must match + pub must: Option>, + + /// All conditions must NOT match + pub must_not: Option>, + + /// At least one of thous conditions should match + pub should: Option>, +} + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct FilterSelector { + pub filter: Filter, +} + +/// +/// Geo filter request Matches coordinates inside the rectangle, described by coordinates of +/// lop-left and bottom-right edges +/// +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct GeoBoundingBox { + /// Geo filter request Matches coordinates inside the rectangle, described by coordinates of + /// lop-left and bottom-right edges + pub bottom_right: GeoPoint, + + /// Geo filter request Matches coordinates inside the rectangle, described by coordinates of + /// lop-left and bottom-right edges + pub top_left: GeoPoint, +} + +/// +/// Geo point payload schema +/// +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct GeoPoint { + /// Geo point payload schema + pub lat: f64, + /// Geo point payload schema + pub lon: f64, +} + +/// +/// Geo filter request Matches coordinates inside the circle of `radius` and center with coordinates `center` +/// +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct GeoRadius { + /// Geo filter request Matches coordinates inside the circle of `radius` and center with + /// coordinates `center` + pub center: GeoPoint, + + /// Radius of the area in meters + pub radius: f64, +} + +/// +/// ID-based filtering condition +/// +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct HasIdCondition { + /// ID-based filtering condition + pub has_id: Vec, +} + +/// +/// Config of HNSW index +/// +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct HnswConfig { + /// Number of neighbours to consider during the index building. Larger the value - more + /// accurate the search, more time required to build index. + pub ef_construct: i64, + + /// Minimal amount of points for additional payload-based indexing. If payload chunk is + /// smaller than `full_scan_threshold` additional indexing won't be used - in this case + /// full-scan search should be preferred by query planner and additional indexing is not + /// required. + pub full_scan_threshold: i64, + + /// Number of edges per node in the index graph. Larger the value - more accurate the search, + /// more space required. + pub m: i64, +} + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct HnswConfigDiff { + /// Number of neighbours to consider during the index building. Larger the value - more + /// accurate the search, more time required to build index. + pub ef_construct: Option, + + /// Minimal amount of points for additional payload-based indexing. If payload chunk is smaller + /// than `full_scan_threshold` additional indexing won't be used - in this case full-scan + /// search should be preferred by query planner and additional indexing is not required. + pub full_scan_threshold: Option, + + /// Number of edges per node in the index graph. Larger the value - more accurate the search, more + /// space required. + pub m: Option, +} + +#[derive(Debug, Clone, Deserialize)] +#[serde(untagged)] +pub enum InlineResponseResult { + CollectionInfo(CollectionInfo), + Bool(bool), + CollectionsResponse(CollectionsResponse), + UpdateResult(UpdateResult), + Record(Record), + RecordList(Vec), + ScrollResult(ScrollResult), + ScoredPointList(Vec), +} + +#[derive(Debug, Clone, Deserialize)] +#[serde(untagged)] +pub enum InlineResponseStatus { + Error(ErrorResponseStatus), + Ok(OkStatus), +} + +#[derive(Debug, Clone, Deserialize)] +pub struct ErrorResponseStatus { + /// Description of the occurred error. + pub error: Option, +} + +#[derive(Debug, Clone, Deserialize)] +pub struct InlineResponse { + /// Time spent to process this request + pub time: Option, + pub status: InlineResponseStatus, + pub result: Option, +} + +/// +/// Match filter request +/// +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct MatchInteger { + /// Integer value to match + pub integer: i64, +} + +/// +/// Match by keyword +/// +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct MatchKeyword { + /// Keyword value to match + pub keyword: String, +} + +#[derive(Debug, Clone, Deserialize)] +pub struct OptimizersConfig { + /// Target amount of segments optimizer will try to keep. Real amount of segments may vary + /// depending on multiple parameters: - Amount of stored points - Current write RPS It is + /// recommended to select default number of segments as a factor of the number of search + /// threads, so that each segment would be handled evenly by one of the threads + pub default_segment_number: i64, + + /// The minimal fraction of deleted vectors in a segment, required to perform segment + /// optimization + pub deleted_threshold: f64, + + /// Minimum interval between forced flushes. + pub flush_interval_sec: i64, + + /// Maximum number of vectors allowed for plain index. Default value based on + /// https://github.com/google-research/google-research/blob/master/scann/docs/algorithms.md + pub indexing_threshold: i64, + + /// Maximum available threads for optimization workers + pub max_optimization_threads: i64, + + /// Do not create segments larger this number of points. Large segments might require + /// disproportionately long indexation times, therefore it makes sense to limit the size of + /// segments. If indexation speed have more priority for your - make this parameter lower. If + /// search speed is more important - make this parameter higher. + pub max_segment_size: i64, + + /// Maximum number of vectors to store in-memory per segment. Segments larger than this + /// threshold will be stored as read-only memmaped file. + pub memmap_threshold: i64, + + /// Starting from this amount of vectors per-segment the engine will start building index for + /// payload. + pub payload_indexing_threshold: i64, + + /// The minimal number of vectors in a segment, required to perform segment optimization + pub vacuum_min_vector_number: i64, +} + +#[derive(Debug, Clone, Deserialize)] +pub struct OptimizersConfigDiff { + /// Target amount of segments optimizer will try to keep. Real amount of segments may vary + /// depending on multiple parameters: - Amount of stored points - Current write RPS It is + /// recommended to select default number of segments as a factor of the number of search + /// threads, so that each segment would be handled evenly by one of the threads + pub default_segment_number: Option, + + /// The minimal fraction of deleted vectors in a segment, required to perform segment + /// optimization + pub deleted_threshold: Option, + + /// Minimum interval between forced flushes. + pub flush_interval_sec: Option, + + /// Maximum number of vectors allowed for plain index. Default value based on + /// https://github.com/google-research/google-research/blob/master/scann/docs/algorithms.md + pub indexing_threshold: Option, + + /// Maximum available threads for optimization workers + pub max_optimization_threads: Option, + + /// Do not create segments larger this number of points. Large segments might require + /// disproportionately long indexation times, therefore it makes sense to limit the size of + /// segments. If indexation speed have more priority for your - make this parameter lower. If + /// search speed is more important - make this parameter higher. + pub max_segment_size: Option, + + /// Maximum number of vectors to store in-memory per segment. Segments larger than this threshold will be stored as read-only memmaped file. + pub memmap_threshold: Option, + + /// Starting from this amount of vectors per-segment the engine will start building index for + /// payload. + pub payload_indexing_threshold: Option, + + /// The minimal number of vectors in a segment, required to perform segment optimization + pub vacuum_min_vector_number: Option, +} + +#[derive(Debug, Clone, Deserialize)] +#[serde(untagged)] +pub enum OptimizersStatus { + Ok(OkStatus), + Error(OptimizersStatusError), +} + +/// +/// Something wrong happened with optimizers +/// +#[derive(Debug, Clone, Deserialize)] +pub struct OptimizersStatusError { + /// Something wrong happened with optimizers + pub error: String, +} + +/// +/// Set payload value, overrides if it is already exists +/// +#[derive(Debug, Clone, Deserialize)] +pub struct PayloadOpsOneOf { + /// Set payload value, overrides if it is already exists + set_payload: SetPayload, +} + +/// +/// Deletes specified payload values if they are assigned +/// +#[derive(Debug, Clone, Deserialize)] +pub struct PayloadOpsOneOf1 { + /// Deletes specified payload values if they are assigned + delete_payload: DeletePayload, +} + +/// +/// Drops all Payload values associated with given points. +/// +#[derive(Debug, Clone, Deserialize)] +pub struct PayloadOpsOneOf2 { + /// Drops all Payload values associated with given points. + clear_payload: PayloadOpsOneOf2ClearPayload, +} + +#[derive(Debug, Clone, Deserialize)] +pub struct PayloadOpsOneOf2ClearPayload { + points: Vec, +} + +/// +/// Clear all Payload values by given filter criteria. +/// +#[derive(Debug, Clone, Deserialize)] +pub struct PayloadOpsOneOf3 { + /// Clear all Payload values by given filter criteria. + pub clear_payload_by_filter: Filter, +} + +/// +/// Payload field type & index information +/// +#[derive(Debug, Clone, Deserialize)] +pub struct PayloadSchemaInfo { + /// Payload field type & index information + pub data_type: PayloadSchemaType, + + /// Payload field type & index information + pub indexed: bool, +} + +#[derive(Debug, Clone, Deserialize)] +pub enum PayloadSchemaType { + Integer(i64), + Float(f64), + Geo(GeoPoint), +} + +#[derive(Debug, Clone, Deserialize)] +pub enum PayloadType { + Integer(i64), + Float(f64), + Geo(GeoPoint), +} + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct PayloadSelectorExclude { + /// Exclude this fields from returning payload + exclude: Vec, +} + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct PayloadSelectorInclude { + /// Only include this payload keys + include: Vec, +} + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct PointIdsList { + points: Vec, +} + +/// +/// Delete point if exists +/// +#[derive(Debug, Clone, Deserialize)] +pub struct PointOperationsOneOf1 { + /// Delete point if exists + delete_points: PointOperationsOneOf1DeletePoints, +} + +#[derive(Debug, Clone, Deserialize)] +pub struct PointOperationsOneOf1DeletePoints { + ids: Vec, +} + +/// +/// Delete points by given filter criteria +/// +#[derive(Debug, Clone, Deserialize)] +pub struct PointOperationsOneOf2 { + /// Delete points by given filter criteria + delete_points_by_filter: Filter, +} + +#[derive(Debug, Clone, Deserialize)] +pub struct PointRequest { + /// Look for points with ids + pub ids: Vec, + + /// Select which payload to return with the response. Default: All + pub with_payload: Option, + + /// Whether to return the point vector with the result? + pub with_vector: Option, +} + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct PointStruct { + /// Id + pub id: ExtendedPointId, + + /// Payload values (optional) + #[serde(skip_serializing_if = "Option::is_none")] + pub payload: Option>, + + /// Vector + pub vector: Vec, +} + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct PointsBatch { + pub batch: Batch, +} + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct PointsList { + pub points: Vec, +} + +/// +/// Range filter request +/// +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct Range { + /// point.key > range.gt + pub gt: Option, + + /// point.key >= range.gte + pub gte: Option, + + /// point.key <= range.lt + pub lt: Option, + + /// point.key <= range.lte + pub lte: Option, +} + +/// +/// Recommendation request. Provides positive and negative examples of the vectors, which are +/// already stored in the collection. Service should look for the points which are closer to +/// positive examples and at the same time further to negative examples. The concrete way of +/// how to compare negative and positive distances is up to implementation in `segment` crate. +/// +#[derive(Debug, Clone, Deserialize)] +pub struct RecommendRequest { + /// Look only for points which satisfies this conditions + filter: Option, + + /// Try to avoid vectors like this + negative: Vec, + + /// Additional search params + params: Option, + + /// Look for vectors closest to those + positive: Vec, + + /// Max number of result to return + top: i64, + + /// Select which payload to return with the response. Default: None + with_payload: Option, + + /// Whether to return the point vector with the result? + with_vector: Option, +} + +/// +/// Point data +/// +#[derive(Debug, Clone, Deserialize)] +pub struct Record { + /// Point data + id: ExtendedPointId, + + /// Payload - values assigned to the point + payload: Option>, + + /// Vector of the point + vector: Option>, +} + +/// +/// Change alias to a new one +/// +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct RenameAlias { + /// Change alias to a new one + new_alias_name: String, + + /// Change alias to a new one + old_alias_name: String, +} + +/// +/// Change alias to a new one +/// +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct RenameAliasOperation { + /// Change alias to a new one + rename_alias: RenameAlias, +} + +/// +/// Search result +/// +#[derive(Debug, Clone, Deserialize)] +pub struct ScoredPoint { + /// Search result + pub id: ExtendedPointId, + + /// Payload - values assigned to the point + pub payload: Option>, + + /// Points vector distance to the query vector + pub score: f64, + + /// Vector of the point + pub vector: Option>, + + /// Point version + pub version: Option, +} + +/// +/// Scroll request - paginate over all points which matches given condition +/// +#[derive(Debug, Clone, Deserialize)] +pub struct ScrollRequest { + /// Look only for points which satisfies this conditions. If not provided - all points. + pub filter: Option, + + /// Limit + pub limit: Option, + + /// Start ID to read points from. + pub offset: Option, + + /// Select which payload to return with the response. Default: All + pub with_payload: Option, + + /// Whether to return the point vector with the result? + pub with_vector: Option, +} + +/// +/// Result of the points read request +/// +#[derive(Debug, Clone, Deserialize)] +pub struct ScrollResult { + /// Offset which should be used to retrieve a next page result + pub next_page_offset: Option, + + /// List of retrieved points + pub points: Vec, +} + +/// +/// Additional parameters of the search +/// +#[derive(Debug, Clone, Deserialize)] +pub struct SearchParams { + /// Params relevant to HNSW index /// Size of the beam in a beam-search. Larger the value - + /// more accurate the result, more time required for search. + pub hnsw_ef: Option, +} + +/// +/// Search request. Holds all conditions and parameters for the search of most similar points +/// by vector similarity given the filtering restrictions. +/// +#[derive(Debug, Clone, Deserialize)] +pub struct SearchRequest { + /// Look only for points which satisfies this conditions + pub filter: Option, + + /// Additional search params + pub params: Option, + + /// Max number of result to return + pub top: i64, + + /// Look for vectors closest to this + pub vector: Vec, + + /// Select which payload to return with the response. Default: None + pub with_payload: Option, + + /// Whether to return the point vector with the result? + pub with_vector: Option, +} + +/// +/// +/// +#[derive(Debug, Clone, Deserialize)] +pub struct SetPayload { + /// payload + pub payload: HashMap, + + /// Assigns payload to each point in this list + pub points: Vec, +} + +#[derive(Debug, Clone, Deserialize)] +pub struct StorageOperationsOneOf { + pub create_collection: CreateCollectionOperation, +} + +#[derive(Debug, Clone, Deserialize)] +pub struct StorageOperationsOneOf1 { + pub update_collection: UpdateCollectionOperation, +} + +#[derive(Debug, Clone, Deserialize)] +pub struct StorageOperationsOneOf2 { + /// Operation for deleting collection with given name + pub delete_collection: String, +} + +#[derive(Debug, Clone, Deserialize)] +pub struct StorageOperationsOneOf3 { + pub change_aliases: ChangeAliasesOperation, +} + +/// +/// Operation for updating parameters of the existing collection +/// +#[derive(Debug, Clone, Deserialize)] +pub struct UpdateCollection { + /// + /// Custom params for Optimizers. If none - values from service configuration file are used. + /// This operation is blocking, it will only proceed ones all current optimizations are + /// complete + /// + pub optimizers_config: Option, +} + +/// +/// Operation for updating parameters of the existing collection +/// +#[derive(Debug, Clone, Deserialize)] +pub struct UpdateCollectionOperation { + /// + /// Operation for updating parameters of the existing collection + /// + pub collection_name: String, + + /// + /// Custom params for Optimizers. If none - values from service configuration file are used. + /// This operation is blocking, it will only proceed ones all current optimizations are + /// complete + /// + pub optimizers_config: Option, +} + +#[derive(Debug, Clone, Deserialize)] +pub struct UpdateResult { + /// + /// Sequential number of the operation + /// + pub operation_id: i64, + + /// + /// Update status + /// + pub status: UpdateStatus, +} diff --git a/src/models/mod.rs b/src/models/mod.rs new file mode 100644 index 0000000..bea7f4d --- /dev/null +++ b/src/models/mod.rs @@ -0,0 +1,3 @@ +mod collection; + +pub use collection::*;