From c4c79da0711ab095895e1c79959e78748ad51f1b Mon Sep 17 00:00:00 2001 From: Ofer Mendelevitch Date: Sat, 19 Aug 2023 13:59:52 -0700 Subject: [PATCH 1/7] Updated usage of metadata so that both part and doc level metadata is returned properly as a single meta-data dict Updated tests --- .../langchain/vectorstores/vectara.py | 26 ++++--- .../vectorstores/test_vectara.py | 77 ++++++++++++------- 2 files changed, 64 insertions(+), 39 deletions(-) diff --git a/libs/langchain/langchain/vectorstores/vectara.py b/libs/langchain/langchain/vectorstores/vectara.py index f263ebeac84..f1c2bc6ca9e 100644 --- a/libs/langchain/langchain/vectorstores/vectara.py +++ b/libs/langchain/langchain/vectorstores/vectara.py @@ -202,12 +202,12 @@ class Vectara(VectorStore): doc_metadata: optional metadata for the document This function indexes all the input text strings in the Vectara corpus as a - single Vectara document, where each input text is considered a "part" and the - metadata are associated with each part. + single Vectara document, where each input text is considered a "section" and the + metadata are associated with each section. if 'doc_metadata' is provided, it is associated with the Vectara document. Returns: - List of ids from adding the texts into the vectorstore. + document ID of the document added """ doc_hash = md5() @@ -307,21 +307,27 @@ class Vectara(VectorStore): result = response.json() responses = result["responseSet"][0]["response"] - vectara_default_metadata = ["lang", "len", "offset"] + documents = result["responseSet"][0]["document"] + + 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.update(doc_md) + metadatas.append(md) + docs = [ ( Document( page_content=x["text"], - metadata={ - m["name"]: m["value"] - for m in x["metadata"] - if m["name"] not in vectara_default_metadata - }, + metadata=md, ), x["score"], ) - for x in responses + for x,md in zip(responses,metadatas) ] + return docs def similarity_search( diff --git a/libs/langchain/tests/integration_tests/vectorstores/test_vectara.py b/libs/langchain/tests/integration_tests/vectorstores/test_vectara.py index 57338e7f994..3b2decfc2f9 100644 --- a/libs/langchain/tests/integration_tests/vectorstores/test_vectara.py +++ b/libs/langchain/tests/integration_tests/vectorstores/test_vectara.py @@ -5,12 +5,14 @@ from langchain.docstore.document import Document from langchain.vectorstores.vectara import Vectara from tests.integration_tests.vectorstores.fake_embeddings import FakeEmbeddings -# For this test to run properly, please setup as follows -# 1. Create a corpus in Vectara, with a filter attribute called "test_num". -# 2. Create an API_KEY for this corpus with permissions for query and indexing -# 3. Setup environment variables: +# +# For this test to run properly, please setup as follows: +# 1. Create a Vectara account: sign up at https://console.vectara.com/signup +# 2. Create a corpus in your Vectara account, with a filter attribute called "test_num". +# 3. Create an API_KEY for this corpus with permissions for query and indexing +# 4. Setup environment variables: # VECTARA_API_KEY, VECTARA_CORPUS_ID and VECTARA_CUSTOMER_ID - +# def get_abbr(s: str) -> str: words = s.split(" ") # Split the string into words @@ -21,38 +23,52 @@ def get_abbr(s: str) -> str: def test_vectara_add_documents() -> None: """Test end to end construction and search.""" - # start with some initial texts - texts = ["grounded generation", "retrieval augmented generation", "data privacy"] - docsearch: Vectara = Vectara.from_texts( - texts, - embedding=FakeEmbeddings(), - metadatas=[ - {"abbr": "gg", "test_num": "1"}, - {"abbr": "rag", "test_num": "1"}, - {"abbr": "dp", "test_num": "1"}, - ], + # create a new Vectara instance + docsearch: Vectara = Vectara() + + # start with some initial texts, added with add_texts + texts1 = ["grounded generation", "retrieval augmented generation", "data privacy"] + md = [{"abbr": get_abbr(t)} for t in texts1] + doc_id1 = docsearch.add_texts( + texts1, + metadatas=md, doc_metadata={"test_num": "1"}, ) - # then add some additional documents - new_texts = ["large language model", "information retrieval", "question answering"] - docsearch.add_documents( - [Document(page_content=t, metadata={"abbr": get_abbr(t)}) for t in new_texts], - doc_metadata={"test_num": "1"}, + # then add some additional documents, now with add_documents + texts2 = ["large language model", "information retrieval", "question answering"] + doc_id2 = docsearch.add_documents( + [Document(page_content=t, metadata={"abbr": get_abbr(t)}) for t in texts2], + doc_metadata={"test_num": "2"}, ) + doc_ids = doc_id1 + doc_id2 - # finally do a similarity search to see if all works okay - output = docsearch.similarity_search( + # test without filter + output1 = docsearch.similarity_search( "large language model", k=2, n_sentence_context=0, + ) + assert len(output1) == 2 + assert output1[0].page_content == "large language model" + assert output1[0].metadata['abbr'] == "llm" + assert output1[1].page_content == "information retrieval" + 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 + output2 = docsearch.similarity_search( + "large language model", + k=1, + n_sentence_context=0, filter="doc.test_num = 1", ) - assert output[0].page_content == "large language model" - assert output[0].metadata == {"abbr": "llm"} - assert output[1].page_content == "information retrieval" - assert output[1].metadata == {"abbr": "ir"} + assert len(output2) == 1 + assert output2[0].page_content == "retrieval augmented generation" + 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.""" @@ -73,8 +89,9 @@ def test_vectara_from_files() -> None: urllib.request.urlretrieve(url, name) files_list.append(name) - docsearch: Vectara = Vectara.from_files( - files=files_list, + docsearch: Vectara = Vectara() + doc_ids = docsearch.add_files( + files_list=files_list, embedding=FakeEmbeddings(), metadatas=[{"url": url, "test_num": "2"} for url in urls], ) @@ -101,7 +118,6 @@ def test_vectara_from_files() -> None: n_sentence_context=1, filter="doc.test_num = 2", ) - print(output[0].page_content) assert output[0].page_content == ( """\ Note the use of “hybrid” in 3) above is different from that used sometimes in the literature, \ @@ -114,3 +130,6 @@ This classification scheme, however, misses a key insight gained in deep learnin models can greatly improve the training of DNNs and other deep discriminative models via better regularization.\ """ # noqa: E501 ) + + for doc_id in doc_ids: + docsearch._delete_doc(doc_id) From 90fd840fb17e6733aa240af51828c99695c5cd53 Mon Sep 17 00:00:00 2001 From: Ofer Mendelevitch Date: Sat, 19 Aug 2023 16:51:53 -0700 Subject: [PATCH 2/7] 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.""" From e92e199ec1e6a042a57fcbcea9ee022fc5432486 Mon Sep 17 00:00:00 2001 From: Ofer Mendelevitch Date: Sat, 19 Aug 2023 16:59:50 -0700 Subject: [PATCH 3/7] fixed lint issue --- .../tests/integration_tests/vectorstores/test_vectara.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/langchain/tests/integration_tests/vectorstores/test_vectara.py b/libs/langchain/tests/integration_tests/vectorstores/test_vectara.py index 5ed1d17343a..8fa3cd7f40d 100644 --- a/libs/langchain/tests/integration_tests/vectorstores/test_vectara.py +++ b/libs/langchain/tests/integration_tests/vectorstores/test_vectara.py @@ -57,7 +57,7 @@ def test_vectara_add_documents() -> None: 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 + # since the query does not match test_num=1 directly we get "RAG" as the result output2 = docsearch.similarity_search( "large language model", k=1, From 8b8d2a65355f5d1f4408bbe63ebcda323dc82b17 Mon Sep 17 00:00:00 2001 From: Ofer Mendelevitch Date: Mon, 28 Aug 2023 22:26:55 -0700 Subject: [PATCH 4/7] fixed similarity_search_with_score to really use a score updated unit test with a test for score threshold Updated demo notebook --- .../integrations/vectorstores/vectara.ipynb | 85 ++++++++++--------- .../langchain/vectorstores/vectara.py | 13 ++- .../vectorstores/test_vectara.py | 13 +++ 3 files changed, 67 insertions(+), 44 deletions(-) diff --git a/docs/extras/integrations/vectorstores/vectara.ipynb b/docs/extras/integrations/vectorstores/vectara.ipynb index bf99823394f..0741c1b1998 100644 --- a/docs/extras/integrations/vectorstores/vectara.ipynb +++ b/docs/extras/integrations/vectorstores/vectara.ipynb @@ -1,7 +1,6 @@ { "cells": [ { - "attachments": {}, "cell_type": "markdown", "id": "683953b3", "metadata": {}, @@ -60,7 +59,6 @@ ] }, { - "attachments": {}, "cell_type": "markdown", "id": "eeead681", "metadata": {}, @@ -73,7 +71,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 1, "id": "04a1f1a0", "metadata": {}, "outputs": [], @@ -86,12 +84,12 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 2, "id": "be0a4973", "metadata": {}, "outputs": [], "source": [ - "loader = TextLoader(\"../../../state_of_the_union.txt\")\n", + "loader = TextLoader(\"../../modules/state_of_the_union.txt\")\n", "documents = loader.load()\n", "text_splitter = CharacterTextSplitter(chunk_size=1000, chunk_overlap=0)\n", "docs = text_splitter.split_documents(documents)" @@ -99,7 +97,7 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 3, "id": "8429667e", "metadata": { "ExecuteTime": { @@ -118,7 +116,6 @@ ] }, { - "attachments": {}, "cell_type": "markdown", "id": "90dbf3e7", "metadata": {}, @@ -133,7 +130,7 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": 4, "id": "85ef3468", "metadata": {}, "outputs": [], @@ -165,7 +162,6 @@ ] }, { - "attachments": {}, "cell_type": "markdown", "id": "1f9215c8", "metadata": { @@ -182,7 +178,7 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": 5, "id": "a8c513ab", "metadata": { "ExecuteTime": { @@ -201,7 +197,7 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 6, "id": "fc516993", "metadata": { "ExecuteTime": { @@ -215,13 +211,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "Tonight. I call on the Senate to: Pass the Freedom to Vote Act. Pass the John Lewis Voting Rights Act. And while you’re at it, pass the Disclose Act so Americans can know who is funding our elections. \n", - "\n", - "Tonight, I’d like to honor someone who has dedicated his life to serve this country: Justice Stephen Breyer—an Army veteran, Constitutional scholar, and retiring Justice of the United States Supreme Court. Justice Breyer, thank you for your service. \n", - "\n", - "One of the most serious constitutional responsibilities a President has is nominating someone to serve on the United States Supreme Court. \n", - "\n", - "And I did that 4 days ago, when I nominated Circuit Court of Appeals Judge Ketanji Brown Jackson. One of our nation’s top legal minds, who will continue Justice Breyer’s legacy of excellence.\n" + "And I did that 4 days ago, when I nominated Circuit Court of Appeals Judge Ketanji Brown Jackson.\n" ] } ], @@ -230,7 +220,6 @@ ] }, { - "attachments": {}, "cell_type": "markdown", "id": "1bda9bf5", "metadata": {}, @@ -242,7 +231,7 @@ }, { "cell_type": "code", - "execution_count": 8, + "execution_count": 7, "id": "8804a21d", "metadata": { "ExecuteTime": { @@ -254,13 +243,13 @@ "source": [ "query = \"What did the president say about Ketanji Brown Jackson\"\n", "found_docs = vectara.similarity_search_with_score(\n", - " query, filter=\"doc.speech = 'state-of-the-union'\"\n", + " query, filter=\"doc.speech = 'state-of-the-union'\", score_threshold=0.2,\n", ")" ] }, { "cell_type": "code", - "execution_count": 9, + "execution_count": 8, "id": "756a6887", "metadata": { "ExecuteTime": { @@ -273,15 +262,9 @@ "name": "stdout", "output_type": "stream", "text": [ - "Tonight. I call on the Senate to: Pass the Freedom to Vote Act. Pass the John Lewis Voting Rights Act. And while you’re at it, pass the Disclose Act so Americans can know who is funding our elections. \n", + "Justice Breyer, thank you for your service. One of the most serious constitutional responsibilities a President has is nominating someone to serve on the United States Supreme Court. And I did that 4 days ago, when I nominated Circuit Court of Appeals Judge Ketanji Brown Jackson. One of our nation’s top legal minds, who will continue Justice Breyer’s legacy of excellence. A former top litigator in private practice.\n", "\n", - "Tonight, I’d like to honor someone who has dedicated his life to serve this country: Justice Stephen Breyer—an Army veteran, Constitutional scholar, and retiring Justice of the United States Supreme Court. Justice Breyer, thank you for your service. \n", - "\n", - "One of the most serious constitutional responsibilities a President has is nominating someone to serve on the United States Supreme Court. \n", - "\n", - "And I did that 4 days ago, when I nominated Circuit Court of Appeals Judge Ketanji Brown Jackson. One of our nation’s top legal minds, who will continue Justice Breyer’s legacy of excellence.\n", - "\n", - "Score: 0.4917977\n" + "Score: 0.786569\n" ] } ], @@ -292,7 +275,6 @@ ] }, { - "attachments": {}, "cell_type": "markdown", "id": "1f9876a8", "metadata": {}, @@ -302,7 +284,7 @@ }, { "cell_type": "code", - "execution_count": 10, + "execution_count": 9, "id": "47784de5", "metadata": {}, "outputs": [ @@ -310,22 +292,43 @@ "name": "stdout", "output_type": "stream", "text": [ - "(Document(page_content='We must forever conduct our struggle on the high plane of dignity and discipline.', metadata={'section': '1'}), 0.7962591)\n", - "(Document(page_content='We must not allow our\\ncreative protests to degenerate into physical violence. . . .', metadata={'section': '1'}), 0.25983918)\n" + "With this threshold of 1.2 we have 0 documents\n" ] } ], "source": [ "query = \"We must forever conduct our struggle\"\n", + "min_score = 1.2\n", "found_docs = vectara.similarity_search_with_score(\n", - " query, filter=\"doc.speech = 'I-have-a-dream'\"\n", + " query, filter=\"doc.speech = 'I-have-a-dream'\", score_threshold=min_score,\n", ")\n", - "print(found_docs[0])\n", - "print(found_docs[1])" + "print(f\"With this threshold of {min_score} we have {len(found_docs)} documents\")" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "id": "3e22949f", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "With this threshold of 0.2 we have 3 documents\n" + ] + } + ], + "source": [ + "query = \"We must forever conduct our struggle\"\n", + "min_score = 0.2\n", + "found_docs = vectara.similarity_search_with_score(\n", + " query, filter=\"doc.speech = 'I-have-a-dream'\", score_threshold=min_score,\n", + ")\n", + "print(f\"With this threshold of {min_score} we have {len(found_docs)} documents\")\n" ] }, { - "attachments": {}, "cell_type": "markdown", "id": "691a82d6", "metadata": {}, @@ -349,7 +352,7 @@ { "data": { "text/plain": [ - "VectaraRetriever(vectorstore=, search_type='similarity', search_kwargs={'lambda_val': 0.025, 'k': 5, 'filter': '', 'n_sentence_context': '0'})" + "VectaraRetriever(tags=['Vectara'], metadata=None, vectorstore=, search_type='similarity', search_kwargs={'lambda_val': 0.025, 'k': 5, 'filter': '', 'n_sentence_context': '2'})" ] }, "execution_count": 11, @@ -376,7 +379,7 @@ { "data": { "text/plain": [ - "Document(page_content='Tonight. I call on the Senate to: Pass the Freedom to Vote Act. Pass the John Lewis Voting Rights Act. And while you’re at it, pass the Disclose Act so Americans can know who is funding our elections. \\n\\nTonight, I’d like to honor someone who has dedicated his life to serve this country: Justice Stephen Breyer—an Army veteran, Constitutional scholar, and retiring Justice of the United States Supreme Court. Justice Breyer, thank you for your service. \\n\\nOne of the most serious constitutional responsibilities a President has is nominating someone to serve on the United States Supreme Court. \\n\\nAnd I did that 4 days ago, when I nominated Circuit Court of Appeals Judge Ketanji Brown Jackson. One of our nation’s top legal minds, who will continue Justice Breyer’s legacy of excellence.', metadata={'source': '../../../state_of_the_union.txt'})" + "Document(page_content='Justice Breyer, thank you for your service. One of the most serious constitutional responsibilities a President has is nominating someone to serve on the United States Supreme Court. And I did that 4 days ago, when I nominated Circuit Court of Appeals Judge Ketanji Brown Jackson. One of our nation’s top legal minds, who will continue Justice Breyer’s legacy of excellence. A former top litigator in private practice.', metadata={'source': 'langchain', 'lang': 'eng', 'offset': '596', 'len': '97', 'speech': 'state-of-the-union'})" ] }, "execution_count": 12, @@ -414,7 +417,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.1" + "version": "3.10.9" } }, "nbformat": 4, diff --git a/libs/langchain/langchain/vectorstores/vectara.py b/libs/langchain/langchain/vectorstores/vectara.py index eee2f1abe1f..a0d836dcc29 100644 --- a/libs/langchain/langchain/vectorstores/vectara.py +++ b/libs/langchain/langchain/vectorstores/vectara.py @@ -245,6 +245,7 @@ class Vectara(VectorStore): k: int = 5, lambda_val: float = 0.025, filter: Optional[str] = None, + score_threshold: Optional[float] = None, n_sentence_context: int = 2, **kwargs: Any, ) -> List[Tuple[Document, float]]: @@ -258,6 +259,8 @@ class Vectara(VectorStore): filter can be "doc.rating > 3.0 and part.lang = 'deu'"} see https://docs.vectara.com/docs/search-apis/sql/filter-overview for more details. + score_threshold: minimal score thresold for the result. + If defined, results with score less than this value will be filtered out. n_sentence_context: number of sentences before/after the matching segment to add, defaults to 2 @@ -305,7 +308,10 @@ class Vectara(VectorStore): result = response.json() - responses = result["responseSet"][0]["response"] + if score_threshold: + responses = [r for r in result["responseSet"][0]["response"] if r["score"] > score_threshold] + else: + responses = result["responseSet"][0]["response"] documents = result["responseSet"][0]["document"] metadatas = [] @@ -316,7 +322,7 @@ class Vectara(VectorStore): md.update(doc_md) metadatas.append(md) - docs = [ + docs_with_score = [ ( Document( page_content=x["text"], @@ -327,7 +333,7 @@ class Vectara(VectorStore): for x, md in zip(responses, metadatas) ] - return docs + return docs_with_score def similarity_search( self, @@ -358,6 +364,7 @@ class Vectara(VectorStore): k=k, lambda_val=lambda_val, filter=filter, + score_threshold=None, n_sentence_context=n_sentence_context, **kwargs, ) diff --git a/libs/langchain/tests/integration_tests/vectorstores/test_vectara.py b/libs/langchain/tests/integration_tests/vectorstores/test_vectara.py index 8fa3cd7f40d..2e79001a1c5 100644 --- a/libs/langchain/tests/integration_tests/vectorstores/test_vectara.py +++ b/libs/langchain/tests/integration_tests/vectorstores/test_vectara.py @@ -68,6 +68,19 @@ def test_vectara_add_documents() -> None: assert output2[0].page_content == "retrieval augmented generation" assert output2[0].metadata["abbr"] == "rag" + # test without filter but with similarity score + # this is similar to the first test, but given the score threshold + # we only get one result + output3 = docsearch.similarity_search_with_score( + "large language model", + k=2, + score_threshold=0.1, + n_sentence_context=0, + ) + assert len(output3) == 1 + assert output3[0][0].page_content == "large language model" + assert output3[0][0].metadata["abbr"] == "llm" + for doc_id in doc_ids: docsearch._delete_doc(doc_id) From a5450be32ed387c5a56c7ddf681f6feef6392578 Mon Sep 17 00:00:00 2001 From: Ofer Mendelevitch Date: Mon, 28 Aug 2023 22:31:39 -0700 Subject: [PATCH 5/7] fixed lint --- libs/langchain/langchain/vectorstores/vectara.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/libs/langchain/langchain/vectorstores/vectara.py b/libs/langchain/langchain/vectorstores/vectara.py index a0d836dcc29..c60048bbb76 100644 --- a/libs/langchain/langchain/vectorstores/vectara.py +++ b/libs/langchain/langchain/vectorstores/vectara.py @@ -260,7 +260,8 @@ class Vectara(VectorStore): https://docs.vectara.com/docs/search-apis/sql/filter-overview for more details. score_threshold: minimal score thresold for the result. - If defined, results with score less than this value will be filtered out. + If defined, results with score less than this value will be + filtered out. n_sentence_context: number of sentences before/after the matching segment to add, defaults to 2 @@ -309,7 +310,11 @@ class Vectara(VectorStore): result = response.json() if score_threshold: - responses = [r for r in result["responseSet"][0]["response"] if r["score"] > score_threshold] + responses = [ + r + for r in result["responseSet"][0]["response"] + if r["score"] > score_threshold + ] else: responses = result["responseSet"][0]["response"] documents = result["responseSet"][0]["document"] From 318a21e2677908267e82fb91be93a106e4ff52dc Mon Sep 17 00:00:00 2001 From: Ofer Mendelevitch Date: Mon, 28 Aug 2023 23:01:11 -0700 Subject: [PATCH 6/7] fixed typo in spelling --- libs/langchain/langchain/vectorstores/vectara.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/langchain/langchain/vectorstores/vectara.py b/libs/langchain/langchain/vectorstores/vectara.py index c60048bbb76..8f041369de0 100644 --- a/libs/langchain/langchain/vectorstores/vectara.py +++ b/libs/langchain/langchain/vectorstores/vectara.py @@ -259,7 +259,7 @@ class Vectara(VectorStore): filter can be "doc.rating > 3.0 and part.lang = 'deu'"} see https://docs.vectara.com/docs/search-apis/sql/filter-overview for more details. - score_threshold: minimal score thresold for the result. + score_threshold: minimal score threshold for the result. If defined, results with score less than this value will be filtered out. n_sentence_context: number of sentences before/after the matching segment From 445420445585a2fa13aef67f1bb38f08f44ba175 Mon Sep 17 00:00:00 2001 From: Ofer Mendelevitch Date: Mon, 28 Aug 2023 23:04:57 -0700 Subject: [PATCH 7/7] reformat black --- libs/langchain/langchain/vectorstores/vectara.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/langchain/langchain/vectorstores/vectara.py b/libs/langchain/langchain/vectorstores/vectara.py index 8f041369de0..9af1124648b 100644 --- a/libs/langchain/langchain/vectorstores/vectara.py +++ b/libs/langchain/langchain/vectorstores/vectara.py @@ -260,7 +260,7 @@ class Vectara(VectorStore): https://docs.vectara.com/docs/search-apis/sql/filter-overview for more details. score_threshold: minimal score threshold for the result. - If defined, results with score less than this value will be + If defined, results with score less than this value will be filtered out. n_sentence_context: number of sentences before/after the matching segment to add, defaults to 2