This pull request introduces several updates and improvements to the backend/open_webui/retrieval/vector.py file. These changes focus on making the system more flexible and configurable by replacing hardcoded values with environment-driven configurations, improving maintainability and adaptability to different deployment environments.
The following changes were made to enhance the functionality and configuration capabilities of the retrieval/vector.py module:
Added
Import of os and int libraries from os and builtins respectively to enable environment-based configurations.
Removed static references to the hardcoded VECTOR_LENGTH to increase adaptability and eliminate redundancy.
Additional Information
Motivation: The hardcoded approach previously used for VECTOR_LENGTH restricted the flexibility of the system. Making VECTOR_LENGTH configurable allows the retrieval module to adapt to different deployments and environments without requiring code changes.
Impact: These changes improve configurability and simplify deployment across environments by leveraging environment variables.
backend/open_webui/retrieval/vector/dbs/pgvector.py: Modified the vector column in the DocumentChunk class to use a configurable vector length from the VECTOR_LENGTH environment variable, with a default of 1536.
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.
## 📋 Pull Request Information
**Original PR:** https://github.com/open-webui/open-webui/pull/8281
**Author:** [@binaryYuki](https://github.com/binaryYuki)
**Created:** 1/2/2025
**Status:** ❌ Closed
**Base:** `dev` ← **Head:** `main`
---
### 📝 Commits (4)
- [`91b647f`](https://github.com/open-webui/open-webui/commit/91b647f998fe4437b93ae99d60d1e2c0264d8432) Make VECTOR_LENGTH configurable in pgvector.py
- [`70106e5`](https://github.com/open-webui/open-webui/commit/70106e522bd738ea134d0f5adafaab89b9531baf) Merge pull request #1 from binaryYuki/configurable-vector-length
- [`7ac8c4e`](https://github.com/open-webui/open-webui/commit/7ac8c4ed3cecbb3181f3966a36a9a6ed2a15096a) Update `pgvector.py` to use configurable vector length
- [`7573c2d`](https://github.com/open-webui/open-webui/commit/7573c2d42a915023a30bb6a8dc0aac3b956e1920) Update env variable name
### 📊 Changes
**1 file changed** (+9 additions, -8 deletions)
<details>
<summary>View changed files</summary>
📝 `backend/open_webui/retrieval/vector/dbs/pgvector.py` (+9 -8)
</details>
### 📄 Description
PR for https://github.com/open-webui/open-webui/discussions/8271
### Description
This pull request introduces several updates and improvements to the backend/open_webui/retrieval/vector.py file. These changes focus on making the system more flexible and configurable by replacing hardcoded values with environment-driven configurations, improving maintainability and adaptability to different deployment environments.
The following changes were made to enhance the functionality and configuration capabilities of the retrieval/vector.py module:
### Added
Import of os and int libraries from os and builtins respectively to enable environment-based configurations.
docs update: https://github.com/open-webui/docs/pull/348
### Changed
* [`backend/open_webui/retrieval/vector/dbs/pgvector.py`](diffhunk://#diff-28a6dc0ae8b8aecb38ddec790ac95fca054271e96eb3ecf2b2cd4cf7a7c1adb2L88-R94): Updated the `adjust_vector_length` method to use `self.vector_length` instead of a hardcoded value.
* [`backend/open_webui/retrieval/vector/dbs/pgvector.py`](diffhunk://#diff-28a6dc0ae8b8aecb38ddec790ac95fca054271e96eb3ecf2b2cd4cf7a7c1adb2L167-R172): Updated the `search` method to use `self.vector_length` for casting vectors.
### Removed
Removed static references to the hardcoded `VECTOR_LENGTH` to increase adaptability and eliminate redundancy.
### Additional Information
- Motivation: The hardcoded approach previously used for VECTOR_LENGTH restricted the flexibility of the system. Making VECTOR_LENGTH configurable allows the retrieval module to adapt to different deployments and environments without requiring code changes.
- Impact: These changes improve configurability and simplify deployment across environments by leveraging environment variables.
Relevant Sections Modified:
* [`backend/open_webui/retrieval/vector/dbs/pgvector.py`](diffhunk://#diff-28a6dc0ae8b8aecb38ddec790ac95fca054271e96eb3ecf2b2cd4cf7a7c1adb2R1): Imported the `os` module to access environment variables.
* [`backend/open_webui/retrieval/vector/dbs/pgvector.py`](diffhunk://#diff-28a6dc0ae8b8aecb38ddec790ac95fca054271e96eb3ecf2b2cd4cf7a7c1adb2L24-R40): Modified the `vector` column in the `DocumentChunk` class to use a configurable vector length from the `VECTOR_LENGTH` environment variable, with a default of 1536.
* [`backend/open_webui/retrieval/vector/dbs/pgvector.py`](diffhunk://#diff-28a6dc0ae8b8aecb38ddec790ac95fca054271e96eb3ecf2b2cd4cf7a7c1adb2L88-R94): Added `self.vector_length` to the `PgvectorClient` class to store the configurable vector length.
---
<sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
📋 Pull Request Information
Original PR: https://github.com/open-webui/open-webui/pull/8281
Author: @binaryYuki
Created: 1/2/2025
Status: ❌ Closed
Base:
dev← Head:main📝 Commits (4)
91b647fMake VECTOR_LENGTH configurable in pgvector.py70106e5Merge pull request #1 from binaryYuki/configurable-vector-length7ac8c4eUpdatepgvector.pyto use configurable vector length7573c2dUpdate env variable name📊 Changes
1 file changed (+9 additions, -8 deletions)
View changed files
📝
backend/open_webui/retrieval/vector/dbs/pgvector.py(+9 -8)📄 Description
PR for https://github.com/open-webui/open-webui/discussions/8271
Description
This pull request introduces several updates and improvements to the backend/open_webui/retrieval/vector.py file. These changes focus on making the system more flexible and configurable by replacing hardcoded values with environment-driven configurations, improving maintainability and adaptability to different deployment environments.
The following changes were made to enhance the functionality and configuration capabilities of the retrieval/vector.py module:
Added
Import of os and int libraries from os and builtins respectively to enable environment-based configurations.
docs update: https://github.com/open-webui/docs/pull/348
Changed
backend/open_webui/retrieval/vector/dbs/pgvector.py: Updated theadjust_vector_lengthmethod to useself.vector_lengthinstead of a hardcoded value.backend/open_webui/retrieval/vector/dbs/pgvector.py: Updated thesearchmethod to useself.vector_lengthfor casting vectors.Removed
Removed static references to the hardcoded
VECTOR_LENGTHto increase adaptability and eliminate redundancy.Additional Information
Motivation: The hardcoded approach previously used for VECTOR_LENGTH restricted the flexibility of the system. Making VECTOR_LENGTH configurable allows the retrieval module to adapt to different deployments and environments without requiring code changes.
Impact: These changes improve configurability and simplify deployment across environments by leveraging environment variables.
Relevant Sections Modified:
backend/open_webui/retrieval/vector/dbs/pgvector.py: Imported theosmodule to access environment variables.backend/open_webui/retrieval/vector/dbs/pgvector.py: Modified thevectorcolumn in theDocumentChunkclass to use a configurable vector length from theVECTOR_LENGTHenvironment variable, with a default of 1536.backend/open_webui/retrieval/vector/dbs/pgvector.py: Addedself.vector_lengthto thePgvectorClientclass to store the configurable vector length.🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.