diff --git a/docs/modules/indexes/chain_examples/chat_vector_db.ipynb b/docs/modules/indexes/chain_examples/chat_vector_db.ipynb index 2df1bc9e..62a007b9 100644 --- a/docs/modules/indexes/chain_examples/chat_vector_db.ipynb +++ b/docs/modules/indexes/chain_examples/chat_vector_db.ipynb @@ -268,12 +268,48 @@ }, { "cell_type": "markdown", - "id": "7fb44daa", - "metadata": {}, + "source": [ + "## Chat Vector DB with `search_distance`\n", + "If you are using a vector store that supports filtering by search distance, you can add a threshold value parameter." + ], + "metadata": { + "collapsed": false + } + }, + { + "cell_type": "code", + "execution_count": null, + "outputs": [], + "source": [ + "vectordbkwargs = {\"search_distance\": 0.9}" + ], + "metadata": { + "collapsed": false + } + }, + { + "cell_type": "code", + "execution_count": null, + "outputs": [], + "source": [ + "qa = ChatVectorDBChain.from_llm(OpenAI(temperature=0), vectorstore, return_source_documents=True)\n", + "chat_history = []\n", + "query = \"What did the president say about Ketanji Brown Jackson\"\n", + "result = qa({\"question\": query, \"chat_history\": chat_history, \"vectordbkwargs\": vectordbkwargs})" + ], + "metadata": { + "collapsed": false + } + }, + { + "cell_type": "markdown", "source": [ "## Chat Vector DB with `map_reduce`\n", "We can also use different types of combine document chains with the Chat Vector DB chain." - ] + ], + "metadata": { + "collapsed": false + } }, { "cell_type": "code", @@ -486,7 +522,7 @@ "source": [ "chat_history = [(query, result[\"answer\"])]\n", "query = \"Did he mention who she suceeded\"\n", - "result = qa({\"question\": query, \"chat_history\": chat_history})" + "result = qa({\"question\": query, \"chat_history\": chat_history})\n" ] } ], diff --git a/langchain/vectorstores/weaviate.py b/langchain/vectorstores/weaviate.py index 9302470b..e1802299 100644 --- a/langchain/vectorstores/weaviate.py +++ b/langchain/vectorstores/weaviate.py @@ -1,7 +1,7 @@ """Wrapper around weaviate vector database.""" from __future__ import annotations -from typing import Any, Iterable, List, Optional +from typing import Any, Dict, Iterable, List, Optional from uuid import uuid4 from langchain.docstore.document import Document @@ -78,7 +78,9 @@ class Weaviate(VectorStore): self, query: str, k: int = 4, **kwargs: Any ) -> List[Document]: """Look up similar documents in weaviate.""" - content = {"concepts": [query]} + content: Dict[str, Any] = {"concepts": [query]} + if kwargs.get("search_distance"): + content["certainty"] = kwargs.get("search_distance") query_obj = self._client.query.get(self._index_name, self._query_attrs) result = query_obj.with_near_text(content).with_limit(k).do() docs = []