community[patch]: LanceDB integration patch update (#20686)

Description : 

- added functionalities - delete, index creation, using existing
connection object etc.
- updated usage 
- Added LaceDB cloud OSS support

make lint_diff , make test checks done
This commit is contained in:
Raghav Dixit
2024-04-24 19:27:43 -04:00
committed by GitHub
parent 9e983c9500
commit 9b7fb381a4
5 changed files with 226 additions and 82 deletions

View File

@@ -1,30 +1,39 @@
from typing import Any
import pytest
from langchain_community.vectorstores import LanceDB
from tests.integration_tests.vectorstores.fake_embeddings import FakeEmbeddings
def import_lancedb() -> Any:
try:
import lancedb
except ImportError as e:
raise ImportError(
"Could not import pinecone lancedb package. "
"Please install it with `pip install lancedb`."
) from e
return lancedb
@pytest.mark.requires("lancedb")
def test_lancedb_with_connection() -> None:
import lancedb
lancedb = import_lancedb()
embeddings = FakeEmbeddings()
db = lancedb.connect("/tmp/lancedb")
db = lancedb.connect("/tmp/lancedb_connection")
texts = ["text 1", "text 2", "item 3"]
vectors = embeddings.embed_documents(texts)
table = db.create_table(
"my_table",
data=[
{"vector": vectors[idx], "id": text, "text": text}
for idx, text in enumerate(texts)
],
mode="overwrite",
)
store = LanceDB(table, embeddings)
store = LanceDB(connection=db, embedding=embeddings)
store.add_texts(texts)
result = store.similarity_search("text 1")
result_texts = [doc.page_content for doc in result]
assert "text 1" in result_texts
store.delete(filter="text = 'text 1'")
assert store.get_table().count_rows() == 2
@pytest.mark.requires("lancedb")
def test_lancedb_without_connection() -> None:

View File

@@ -67,6 +67,7 @@ def test_compatible_vectorstore_documentation() -> None:
"FAISS",
"HanaDB",
"InMemoryVectorStore",
"LanceDB",
"Milvus",
"MomentoVectorIndex",
"MyScale",