Elffuss BraidHub

kikocis/lancedb public

feat(rust): allow `add_embedding` on `create_empty_table` (#1754)

Fixes https://github.com/lancedb/lancedb/issues/1750
Changeseta7ea54e1c0d986e8b3f4db5aaa41932b34e95badda9b9bf814c3eae711c337af
AuthorWill Jones <willjones127@gmail.com> · 2024-10-17 11:58 -07:00
CommitterGitHub <noreply@github.com> · 2024-10-17 11:58 -07:00
Parents29678251014b

Browse the files at this changeset

1 file changed

modified rust/lancedb/src/connection.rs +20 −16
@@ -196,22 +196,6 @@
196196 };
197197 Ok((data, builder))
198198 }
199-
200- pub fn add_embedding(mut self, definition: EmbeddingDefinition) -> Result<Self> {
201- // Early verification of the embedding name
202- let embedding_func = self
203- .parent
204- .embedding_registry()
205- .get(&definition.embedding_name)
206- .ok_or_else(|| Error::EmbeddingFunctionNotFound {
207- name: definition.embedding_name.clone(),
208- reason: "No embedding function found in the connection's embedding_registry"
209- .to_string(),
210- })?;
211-
212- self.embeddings.push((definition, embedding_func));
213- Ok(self)
214- }
215199 }
216200
217201 // Builder methods that only apply when we do not have initial data
@@ -329,6 +313,26 @@
329313 };
330314 self
331315 }
316+
317+ /// Add an embedding definition to the table.
318+ ///
319+ /// The `embedding_name` must match the name of an embedding function that
320+ /// was previously registered with the connection's [`EmbeddingRegistry`].
321+ pub fn add_embedding(mut self, definition: EmbeddingDefinition) -> Result<Self> {
322+ // Early verification of the embedding name
323+ let embedding_func = self
324+ .parent
325+ .embedding_registry()
326+ .get(&definition.embedding_name)
327+ .ok_or_else(|| Error::EmbeddingFunctionNotFound {
328+ name: definition.embedding_name.clone(),
329+ reason: "No embedding function found in the connection's embedding_registry"
330+ .to_string(),
331+ })?;
332+
333+ self.embeddings.push((definition, embedding_func));
334+ Ok(self)
335+ }
332336 }
333337
334338 #[derive(Clone, Debug)]