-
-
Notifications
You must be signed in to change notification settings - Fork 54
[16.0][ADD] field_vector_config #90
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
etobella
wants to merge
4
commits into
OCA:16.0
Choose a base branch
from
dixmit:16.0-add-field_vector_config
base: 16.0
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,6 +9,13 @@ on: | |
| - "16.0" | ||
| - "16.0-ocabot-*" | ||
|
|
||
| <<<<<<< before updating | ||
| ======= | ||
| concurrency: | ||
| group: ${{ github.workflow }}-${{ github.ref }} | ||
| cancel-in-progress: true | ||
|
|
||
| >>>>>>> after updating | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. there is another merge conflict here 😬 |
||
| jobs: | ||
| unreleased-deps: | ||
| runs-on: ubuntu-latest | ||
|
|
@@ -42,7 +49,7 @@ jobs: | |
| makepot: "true" | ||
| services: | ||
| postgres: | ||
| image: postgres:12 | ||
| image: pgvector/pgvector:pg16 | ||
| env: | ||
| POSTGRES_USER: odoo | ||
| POSTGRES_PASSWORD: odoo | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,149 @@ | ||
| .. image:: https://odoo-community.org/readme-banner-image | ||
| :target: https://odoo-community.org/get-involved?utm_source=readme | ||
| :alt: Odoo Community Association | ||
|
|
||
| ================= | ||
| Field Vector Fill | ||
| ================= | ||
|
|
||
| .. | ||
| !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
| !! This file is generated by oca-gen-addon-readme !! | ||
| !! changes will be overwritten. !! | ||
| !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
| !! source digest: sha256:722ec05a7f6f24bb142697333fdd71c40ae7a2539242bd672c0affe2056d77c6 | ||
| !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
|
|
||
| .. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png | ||
| :target: https://odoo-community.org/page/development-status | ||
| :alt: Beta | ||
| .. |badge2| image:: https://img.shields.io/badge/license-AGPL--3-blue.png | ||
| :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html | ||
| :alt: License: AGPL-3 | ||
| .. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fai-lightgray.png?logo=github | ||
| :target: https://github.com/OCA/ai/tree/16.0/field_vector_config | ||
| :alt: OCA/ai | ||
| .. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png | ||
| :target: https://translation.odoo-community.org/projects/ai-16-0/ai-16-0-field_vector_config | ||
| :alt: Translate me on Weblate | ||
| .. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png | ||
| :target: https://runboat.odoo-community.org/builds?repo=OCA/ai&target_branch=16.0 | ||
| :alt: Try me on Runboat | ||
|
|
||
| |badge1| |badge2| |badge3| |badge4| |badge5| | ||
|
|
||
| This module allows to configure vector fields dynamically. Quite | ||
| interesting if you want to handle them by using AI. | ||
|
|
||
| **Table of contents** | ||
|
|
||
| .. contents:: | ||
| :local: | ||
|
|
||
| Use Cases / Context | ||
| =================== | ||
|
|
||
| The original field_vector module implements vector configuration, | ||
| however, it is hard to handle how to create and search them. | ||
|
|
||
| With this module, we added the functionality to do it. | ||
|
|
||
| Configuration | ||
| ============= | ||
|
|
||
| With this module, we can easily add a configuration on a vector to | ||
| configure it dynamically on our database. | ||
|
|
||
| .. code:: python | ||
|
|
||
| from odoo.addons.field_vector_config.fields import ComputedVector | ||
|
|
||
|
|
||
| class ResPartner(models.Model): | ||
| _inherit = "res.partner" | ||
|
|
||
| embedding = ComputedVector(string="Embedding") | ||
|
|
||
| With that, we can go to **Settings / Technical / Database Structure** to | ||
| add the field manually and configure it. There you can configure the | ||
| size of the vector (depends on the method and model), computation | ||
| information and so on. | ||
|
|
||
| Important notes: | ||
|
|
||
| - If you make a field that is computed, we recommend to create it in a | ||
| pre_init_hook to avoid the creation and allow the user to configure it | ||
| properly | ||
| - If you change the size of the vector, update the column. It will | ||
| update the size and do nothing if it has the proper size. | ||
|
|
||
| Usage | ||
| ===== | ||
|
|
||
| After the configuration, we can easily compute and search using this | ||
| vector. For example: | ||
|
|
||
| .. code:: python | ||
|
|
||
| from odoo.addons.ai_tool.tools import aitool | ||
|
|
||
|
|
||
| class ProductProduct(models.Model): | ||
|
|
||
| _inherit = "product.product" | ||
|
|
||
| product_vector = ComputedVector( | ||
| compute="_compute_product_vector", | ||
| store=True, | ||
| ) | ||
|
|
||
| @api.depends("name", "description") | ||
| def _compute_product_vector(self): | ||
| for record in self: | ||
| record.product_vector = record._encode_vector("product_vector", f"{record.name}\n{record.description}\n{record.description_purchase}")[0] | ||
|
|
||
| def _find_vector_product(self, value, limit=5): | ||
| records = self.search_vector("product_vector", value, limit=limit) | ||
| return [{"id": r.id, "name": r.name, "description": r.description} for r in records] | ||
|
|
||
| Bug Tracker | ||
| =========== | ||
|
|
||
| Bugs are tracked on `GitHub Issues <https://github.com/OCA/ai/issues>`_. | ||
| In case of trouble, please check there if your issue has already been reported. | ||
| If you spotted it first, help us to smash it by providing a detailed and welcomed | ||
| `feedback <https://github.com/OCA/ai/issues/new?body=module:%20field_vector_config%0Aversion:%2016.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_. | ||
|
|
||
| Do not contact contributors directly about support or help with technical issues. | ||
|
|
||
| Credits | ||
| ======= | ||
|
|
||
| Authors | ||
| ------- | ||
|
|
||
| * Dixmit | ||
|
|
||
| Contributors | ||
| ------------ | ||
|
|
||
| - `Dixmit <https://www.dixmit.com>`__ | ||
|
|
||
| - Enric Tobella | ||
|
|
||
| Maintainers | ||
| ----------- | ||
|
|
||
| This module is maintained by the OCA. | ||
|
|
||
| .. image:: https://odoo-community.org/logo.png | ||
| :alt: Odoo Community Association | ||
| :target: https://odoo-community.org | ||
|
|
||
| OCA, or the Odoo Community Association, is a nonprofit organization whose | ||
| mission is to support the collaborative development of Odoo features and | ||
| promote its widespread use. | ||
|
|
||
| This module is part of the `OCA/ai <https://github.com/OCA/ai/tree/16.0/field_vector_config>`_ project on GitHub. | ||
|
|
||
| You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| from . import models | ||
| from . import fields |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| # Copyright 2026 Dixmit | ||
| # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
|
|
||
| { | ||
| "name": "Field Vector Fill", | ||
| "summary": """Autogenerate vectors and add search functions""", | ||
| "version": "16.0.1.0.0", | ||
| "license": "AGPL-3", | ||
| "author": "Dixmit,Odoo Community Association (OCA)", | ||
| "website": "https://github.com/OCA/ai", | ||
| "depends": [ | ||
| "field_vector", | ||
| ], | ||
| "data": [ | ||
| "security/ir.model.access.csv", | ||
| "views/ir_model_field_vector.xml", | ||
| ], | ||
| "demo": [], | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| # Copyright 2026 Dixmit | ||
| # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
|
|
||
| from odoo.addons.field_vector.fields import Vector | ||
|
|
||
|
|
||
| def split_text_chunks(text, max_words=350, overlap=50): | ||
| words = text.split() | ||
| chunks = [] | ||
| start = 0 | ||
| while start < len(words): | ||
| chunk = " ".join(words[start : start + max_words]) | ||
| chunks.append(chunk) | ||
| start += max_words - overlap | ||
| return chunks | ||
|
|
||
|
|
||
| class ComputedVector(Vector): | ||
| type = "computed_vector" | ||
|
|
||
| def __init__( | ||
| self, | ||
| dimensions=10, | ||
| **kwargs, | ||
| ): | ||
| # We set a default dimensions value | ||
| super().__init__(dimensions=dimensions, **kwargs) | ||
|
|
||
| @property | ||
| def column_type(self): | ||
| return ("vector", "vector") | ||
|
|
||
| def vector_dimensions(self, model): | ||
| dimensions = ( | ||
| model.env["ir.model.fields"] | ||
| .sudo() | ||
| .search( | ||
| [("model", "=", model._name), ("name", "=", self.name)], | ||
| limit=1, | ||
| ) | ||
| .vector_configuration_ids.dimensions | ||
| ) | ||
| return dimensions or super().vector_dimensions(model) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| from . import ir_model_field_vector | ||
| from . import ir_model_fields | ||
| from . import base |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.