From 90fd840fb17e6733aa240af51828c99695c5cd53 Mon Sep 17 00:00:00 2001 From: Ofer Mendelevitch Date: Sat, 19 Aug 2023 16:51:53 -0700 Subject: [PATCH] fixed formatting --- libs/langchain/langchain/vectorstores/vectara.py | 8 ++++---- .../tests/integration_tests/vectorstores/test_vectara.py | 8 +++++--- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/libs/langchain/langchain/vectorstores/vectara.py b/libs/langchain/langchain/vectorstores/vectara.py index f1c2bc6ca9e..cd8ee9c9fad 100644 --- a/libs/langchain/langchain/vectorstores/vectara.py +++ b/libs/langchain/langchain/vectorstores/vectara.py @@ -311,9 +311,9 @@ class Vectara(VectorStore): metadatas = [] for x in responses: - md = { m["name"]: m["value"] for m in x["metadata"] } - doc_num = x['documentIndex'] - doc_md = { m["name"]: m["value"] for m in documents[doc_num]['metadata'] } + md = {m["name"]: m["value"] for m in x["metadata"]} + doc_num = x["documentIndex"] + doc_md = {m["name"]: m["value"] for m in documents[doc_num]["metadata"]} md.update(doc_md) metadatas.append(md) @@ -325,7 +325,7 @@ class Vectara(VectorStore): ), x["score"], ) - for x,md in zip(responses,metadatas) + for x, md in zip(responses, metadatas) ] return docs diff --git a/libs/langchain/tests/integration_tests/vectorstores/test_vectara.py b/libs/langchain/tests/integration_tests/vectorstores/test_vectara.py index 3b2decfc2f9..5ed1d17343a 100644 --- a/libs/langchain/tests/integration_tests/vectorstores/test_vectara.py +++ b/libs/langchain/tests/integration_tests/vectorstores/test_vectara.py @@ -14,6 +14,7 @@ from tests.integration_tests.vectorstores.fake_embeddings import FakeEmbeddings # VECTARA_API_KEY, VECTARA_CORPUS_ID and VECTARA_CUSTOMER_ID # + def get_abbr(s: str) -> str: words = s.split(" ") # Split the string into words first_letters = [word[0] for word in words] # Extract the first letter of each word @@ -51,9 +52,9 @@ def test_vectara_add_documents() -> None: ) assert len(output1) == 2 assert output1[0].page_content == "large language model" - assert output1[0].metadata['abbr'] == "llm" + assert output1[0].metadata["abbr"] == "llm" assert output1[1].page_content == "information retrieval" - assert output1[1].metadata['abbr'] == "ir" + assert output1[1].metadata["abbr"] == "ir" # test with metadata filter (doc level) # since the query does not match test_num=1 directly we get RAG as the matching result @@ -65,11 +66,12 @@ def test_vectara_add_documents() -> None: ) assert len(output2) == 1 assert output2[0].page_content == "retrieval augmented generation" - assert output2[0].metadata['abbr'] == "rag" + assert output2[0].metadata["abbr"] == "rag" for doc_id in doc_ids: docsearch._delete_doc(doc_id) + def test_vectara_from_files() -> None: """Test end to end construction and search."""