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

Method new

src/models/collection.rs:151–310  ·  view source on GitHub ↗
(
        name: String,
        description: Option<String>,
        dense_vector_options: DenseVectorOptions,
        sparse_vector_options: SparseVectorOptions,
        tf_idf_options: TFIDFOptions,

Source from the content-addressed store, hash-verified

149impl Collection {
150 #[allow(clippy::too_many_arguments)]
151 pub fn new(
152 name: String,
153 description: Option<String>,
154 dense_vector_options: DenseVectorOptions,
155 sparse_vector_options: SparseVectorOptions,
156 tf_idf_options: TFIDFOptions,
157 key_value_options: KeyValueOptions,
158 usv_options: USVOptions,
159 metadata_schema: Option<MetadataSchema>,
160 collection_config: CollectionConfig,
161 store_raw_text: bool,
162 lmdb: MetaDb,
163 current_version: VersionNumber,
164 vcs: VersionControl,
165 ctx: &AppContext,
166 ) -> Result<Arc<Self>, WaCustomError> {
167 if name.is_empty() {
168 return Err(WaCustomError::InvalidParams);
169 }
170
171 let collection_path: Arc<Path> = get_collections_path().join(&name).into();
172 fs::create_dir_all(&collection_path).map_err(|e| WaCustomError::FsError(e.to_string()))?;
173
174 let internal_to_external_map_dim_file = OpenOptions::new()
175 .read(true)
176 .write(true)
177 .truncate(false)
178 .create(true)
179 .open(collection_path.join("itoe.dim"))
180 .map_err(BufIoError::Io)?;
181
182 let internal_to_external_map_dim_bufman =
183 BufferManager::new(internal_to_external_map_dim_file, 8192).map_err(BufIoError::Io)?;
184
185 let internal_to_external_map_data_bufmans = BufferManagerFactory::new(
186 collection_path.clone(),
187 |root, version: &VersionNumber| root.join(format!("itoe.{}.data", **version)),
188 8192,
189 );
190
191 let external_to_internal_map_dim_file = OpenOptions::new()
192 .read(true)
193 .write(true)
194 .truncate(false)
195 .create(true)
196 .open(collection_path.join("etoi.dim"))
197 .map_err(BufIoError::Io)?;
198
199 let external_to_internal_map_dim_bufman =
200 BufferManager::new(external_to_internal_map_dim_file, 8192).map_err(BufIoError::Io)?;
201
202 let external_to_internal_map_data_bufmans = BufferManagerFactory::new(
203 collection_path.clone(),
204 |root, version: &VersionNumber| root.join(format!("etoi.{}.data", **version)),
205 8192,
206 );
207
208 let document_to_internals_map_dim_file = OpenOptions::new()

Callers

nothing calls this directly

Calls 5

get_collections_pathFunction · 0.85
cloneMethod · 0.80
pre_commitMethod · 0.80
is_emptyMethod · 0.45
readMethod · 0.45

Tested by

no test coverage detected