fix(python)!: handle bad openai embeddings gracefully (#1873)

BREAKING-CHANGE: change Pydantic Vector field to be nullable by default.
Closes #1577
This commit is contained in:
Lei Xu
2024-11-23 13:33:52 -08:00
committed by GitHub
parent dfd9d2ac99
commit 2ded17452b
7 changed files with 102 additions and 63 deletions

View File

@@ -90,10 +90,13 @@ def test_embedding_with_bad_results(tmp_path):
self, texts: Union[List[str], np.ndarray]
) -> list[Union[np.array, None]]:
# Return None, which is bad if field is non-nullable
return [
None if i % 2 == 0 else np.random.randn(self.ndims())
a = [
np.full(self.ndims(), np.nan)
if i % 2 == 0
else np.random.randn(self.ndims())
for i in range(len(texts))
]
return a
db = lancedb.connect(tmp_path)
registry = EmbeddingFunctionRegistry.get_instance()