MCPcopy Create free account
hub / github.com/cosdata/cosdata / init_inverted_index_for_collection

Function init_inverted_index_for_collection

src/api_service.rs:219–239  ·  view source on GitHub ↗

creates an inverted index for a collection

(
    ctx: Arc<AppContext>,
    collection: &Collection,
    quantization_bits: u8,
    sample_threshold: usize,
)

Source from the content-addressed store, hash-verified

217
218/// creates an inverted index for a collection
219pub async fn init_inverted_index_for_collection(
220 ctx: Arc<AppContext>,
221 collection: &Collection,
222 quantization_bits: u8,
223 sample_threshold: usize,
224) -> Result<Arc<InvertedIndex>, WaCustomError> {
225 let collection_path: Arc<Path> = collection.get_path();
226 let index_path = collection_path.join("sparse_inverted_index");
227 fs::create_dir_all(&index_path).map_err(|e| WaCustomError::FsError(e.to_string()))?;
228
229 let index = Arc::new(InvertedIndex::new(
230 index_path.clone(),
231 quantization_bits,
232 sample_threshold,
233 )?);
234
235 ctx.ain_env
236 .collections_map
237 .insert_inverted_index(collection, index.clone())?;
238 Ok(index)
239}
240
241/// creates an inverted index for a collection
242pub async fn init_tf_idf_index_for_collection(

Callers 1

create_sparse_indexFunction · 0.85

Calls 3

get_pathMethod · 0.80
cloneMethod · 0.80
insert_inverted_indexMethod · 0.80

Tested by

no test coverage detected