mirror of
https://github.com/hwchase17/langchain.git
synced 2025-06-01 12:38:45 +00:00
Implementation is similar to search_distance and where_filter # adds 'additional' support to Weaviate queries Co-authored-by: Dev 2049 <dev.dev2049@gmail.com>
This commit is contained in:
parent
87bba2e8d3
commit
b950022894
@ -195,6 +195,8 @@ class Weaviate(VectorStore):
|
||||
query_obj = self._client.query.get(self._index_name, self._query_attrs)
|
||||
if kwargs.get("where_filter"):
|
||||
query_obj = query_obj.with_where(kwargs.get("where_filter"))
|
||||
if kwargs.get("additional"):
|
||||
query_obj = query_obj.with_additional(kwargs.get("additional"))
|
||||
result = query_obj.with_near_text(content).with_limit(k).do()
|
||||
if "errors" in result:
|
||||
raise ValueError(f"Error during query: {result['errors']}")
|
||||
@ -212,6 +214,8 @@ class Weaviate(VectorStore):
|
||||
query_obj = self._client.query.get(self._index_name, self._query_attrs)
|
||||
if kwargs.get("where_filter"):
|
||||
query_obj = query_obj.with_where(kwargs.get("where_filter"))
|
||||
if kwargs.get("additional"):
|
||||
query_obj = query_obj.with_additional(kwargs.get("additional"))
|
||||
result = query_obj.with_near_vector(vector).with_limit(k).do()
|
||||
if "errors" in result:
|
||||
raise ValueError(f"Error during query: {result['errors']}")
|
||||
|
@ -81,6 +81,28 @@ class TestWeaviate:
|
||||
)
|
||||
assert output == [Document(page_content="foo", metadata={"page": 0})]
|
||||
|
||||
@pytest.mark.vcr(ignore_localhost=True)
|
||||
def test_similarity_search_with_metadata_and_additional(
|
||||
self, weaviate_url: str, embedding_openai: OpenAIEmbeddings
|
||||
) -> None:
|
||||
"""Test end to end construction and search with metadata and additional."""
|
||||
texts = ["foo", "bar", "baz"]
|
||||
metadatas = [{"page": i} for i in range(len(texts))]
|
||||
docsearch = Weaviate.from_texts(
|
||||
texts, embedding_openai, metadatas=metadatas, weaviate_url=weaviate_url
|
||||
)
|
||||
output = docsearch.similarity_search(
|
||||
"foo",
|
||||
k=1,
|
||||
additional=["certainty"],
|
||||
)
|
||||
assert output == [
|
||||
Document(
|
||||
page_content="foo",
|
||||
metadata={"page": 0, "_additional": {"certainty": 1}},
|
||||
)
|
||||
]
|
||||
|
||||
@pytest.mark.vcr(ignore_localhost=True)
|
||||
def test_similarity_search_with_uuids(
|
||||
self, weaviate_url: str, embedding_openai: OpenAIEmbeddings
|
||||
|
Loading…
Reference in New Issue
Block a user