From fd6b0398591aa59b31879bef1f701ec18cb93fd8 Mon Sep 17 00:00:00 2001 From: Vineeth B V <37930821+vinsdragonis@users.noreply.github.com> Date: Thu, 6 Feb 2025 12:04:14 +0530 Subject: [PATCH 1/5] Added a query method for OpenSearch vector db. - This PR aims to address the error 400: "**'OpenSearchClient' object has no attribute 'query'**". - With the implemented query() method, this issue should be resolved and allow uploaded documents to be vectorized and retrieved based on the given query. --- .../retrieval/vector/dbs/opensearch.py | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/backend/open_webui/retrieval/vector/dbs/opensearch.py b/backend/open_webui/retrieval/vector/dbs/opensearch.py index b3d8b5eb8..c4732e1bc 100644 --- a/backend/open_webui/retrieval/vector/dbs/opensearch.py +++ b/backend/open_webui/retrieval/vector/dbs/opensearch.py @@ -113,6 +113,40 @@ class OpenSearchClient: return self._result_to_search_result(result) + def query( + self, index_name: str, filter: dict, limit: Optional[int] = None + ) -> Optional[GetResult]: + if not self.has_collection(index_name): + return None + + query_body = { + "query": { + "bool": { + "filter": [] + } + }, + "_source": ["text", "metadata"], + } + + for field, value in filter.items(): + query_body["query"]["bool"]["filter"].append({ + "term": {field: value} + }) + + size = limit if limit else 10 + + try: + result = self.client.search( + index=f"{self.index_prefix}_{index_name}", + body=query_body, + size=size + ) + + return self._result_to_get_result(result) + + except Exception as e: + return None + def get_or_create_index(self, index_name: str, dimension: int): if not self.has_index(index_name): self._create_index(index_name, dimension) From 7c78facfd9ae16c69df93dcf7e8ce3e2ea5744be Mon Sep 17 00:00:00 2001 From: Vineeth B V <37930821+vinsdragonis@users.noreply.github.com> Date: Thu, 6 Feb 2025 13:36:11 +0530 Subject: [PATCH 2/5] Update opensearch.py --- backend/open_webui/retrieval/vector/dbs/opensearch.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/backend/open_webui/retrieval/vector/dbs/opensearch.py b/backend/open_webui/retrieval/vector/dbs/opensearch.py index c4732e1bc..41d634391 100644 --- a/backend/open_webui/retrieval/vector/dbs/opensearch.py +++ b/backend/open_webui/retrieval/vector/dbs/opensearch.py @@ -114,9 +114,9 @@ class OpenSearchClient: return self._result_to_search_result(result) def query( - self, index_name: str, filter: dict, limit: Optional[int] = None + self, collection_name: str, filter: dict, limit: Optional[int] = None ) -> Optional[GetResult]: - if not self.has_collection(index_name): + if not self.has_collection(collection_name): return None query_body = { @@ -137,7 +137,7 @@ class OpenSearchClient: try: result = self.client.search( - index=f"{self.index_prefix}_{index_name}", + index=f"{self.index_prefix}_{collection_name}", body=query_body, size=size ) From 5a1652bc63065f5be7815945afd8674de7a4314c Mon Sep 17 00:00:00 2001 From: Vineeth B V <37930821+vinsdragonis@users.noreply.github.com> Date: Sun, 9 Feb 2025 16:14:41 +0530 Subject: [PATCH 3/5] Update requirements.txt --- backend/requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/requirements.txt b/backend/requirements.txt index 14ad4b9cd..0e75244fd 100644 --- a/backend/requirements.txt +++ b/backend/requirements.txt @@ -45,7 +45,7 @@ fake-useragent==1.5.1 chromadb==0.6.2 pymilvus==2.5.0 qdrant-client~=1.12.0 -opensearch-py==2.7.1 +opensearch-py==2.8.0 transformers From b9d049cb05ef229140a0416ce6a14c898c30cb36 Mon Sep 17 00:00:00 2001 From: Vineeth B V <37930821+vinsdragonis@users.noreply.github.com> Date: Sun, 9 Feb 2025 16:43:34 +0530 Subject: [PATCH 4/5] Create OpenSearch docker setup.md --- docs/OpenSearch docker setup.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 docs/OpenSearch docker setup.md diff --git a/docs/OpenSearch docker setup.md b/docs/OpenSearch docker setup.md new file mode 100644 index 000000000..850e20b09 --- /dev/null +++ b/docs/OpenSearch docker setup.md @@ -0,0 +1,13 @@ +# Setup +- This addresses the setup process between only Open-WebUI and OpenSearch. +- This does not get into the details regarding Ollama, OpenAI, or their models. + +## Steps +1. `Docker pull` the images for OpenSearch and Open-WebUI +2. Setup a docker network as these services need to be on the same network to interact with each other correctly. For more info, refer to [Creating a docker network](https://docs.docker.com/reference/cli/docker/network/create/) +3. For the setup process of OpenSearch, refer to [OpenSearch docker setup](https://opensearch.org/docs/latest/install-and-configure/install-opensearch/docker/) +4. To set Open-WebUI to use OpenSearch as the vector database, refer to [Open-WebUI RAG setup](https://docs.openwebui.com/getting-started/env-configuration#retrieval-augmented-generation-rag) and [OpenSearch environment variables](https://docs.openwebui.com/getting-started/env-configuration#opensearch) +5. Ensure that both OpenSearch and Open-WebUI are running within the same docker network by specifying the same in your `docker run` command + +## Short note +- While performing the setup process, it is recommended to use OpenSearch with **SSL enabled** as some functionalities will not work on HTTP, but rather on HTTPS, even if not explicitly mentioned. From 40bba83cee82a376ecd68c74396e63e28334ba95 Mon Sep 17 00:00:00 2001 From: Timothy Jaeryang Baek Date: Sun, 9 Feb 2025 13:06:05 -0800 Subject: [PATCH 5/5] Delete docs/OpenSearch docker setup.md --- docs/OpenSearch docker setup.md | 13 ------------- 1 file changed, 13 deletions(-) delete mode 100644 docs/OpenSearch docker setup.md diff --git a/docs/OpenSearch docker setup.md b/docs/OpenSearch docker setup.md deleted file mode 100644 index 850e20b09..000000000 --- a/docs/OpenSearch docker setup.md +++ /dev/null @@ -1,13 +0,0 @@ -# Setup -- This addresses the setup process between only Open-WebUI and OpenSearch. -- This does not get into the details regarding Ollama, OpenAI, or their models. - -## Steps -1. `Docker pull` the images for OpenSearch and Open-WebUI -2. Setup a docker network as these services need to be on the same network to interact with each other correctly. For more info, refer to [Creating a docker network](https://docs.docker.com/reference/cli/docker/network/create/) -3. For the setup process of OpenSearch, refer to [OpenSearch docker setup](https://opensearch.org/docs/latest/install-and-configure/install-opensearch/docker/) -4. To set Open-WebUI to use OpenSearch as the vector database, refer to [Open-WebUI RAG setup](https://docs.openwebui.com/getting-started/env-configuration#retrieval-augmented-generation-rag) and [OpenSearch environment variables](https://docs.openwebui.com/getting-started/env-configuration#opensearch) -5. Ensure that both OpenSearch and Open-WebUI are running within the same docker network by specifying the same in your `docker run` command - -## Short note -- While performing the setup process, it is recommended to use OpenSearch with **SSL enabled** as some functionalities will not work on HTTP, but rather on HTTPS, even if not explicitly mentioned.