Skip to content

Commit 68df69d

Browse files
committed
[MIG] field_vector: Migration to 18.0
1 parent 2c7fdce commit 68df69d

7 files changed

Lines changed: 59 additions & 68 deletions

File tree

field_vector/README.rst

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
.. image:: https://odoo-community.org/readme-banner-image
2-
:target: https://odoo-community.org/get-involved?utm_source=readme
3-
:alt: Odoo Community Association
4-
51
============
62
Field Vector
73
============
@@ -17,17 +13,17 @@ Field Vector
1713
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
1814
:target: https://odoo-community.org/page/development-status
1915
:alt: Beta
20-
.. |badge2| image:: https://img.shields.io/badge/license-LGPL--3-blue.png
16+
.. |badge2| image:: https://img.shields.io/badge/licence-LGPL--3-blue.png
2117
:target: http://www.gnu.org/licenses/lgpl-3.0-standalone.html
2218
:alt: License: LGPL-3
2319
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fserver--tools-lightgray.png?logo=github
24-
:target: https://github.com/OCA/server-tools/tree/16.0/field_vector
20+
:target: https://github.com/OCA/server-tools/tree/18.0/field_vector
2521
:alt: OCA/server-tools
2622
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
27-
:target: https://translation.odoo-community.org/projects/server-tools-16-0/server-tools-16-0-field_vector
23+
:target: https://translation.odoo-community.org/projects/server-tools-18-0/server-tools-18-0-field_vector
2824
:alt: Translate me on Weblate
2925
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
30-
:target: https://runboat.odoo-community.org/builds?repo=OCA/server-tools&target_branch=16.0
26+
:target: https://runboat.odoo-community.org/builds?repo=OCA/server-tools&target_branch=18.0
3127
:alt: Try me on Runboat
3228

3329
|badge1| |badge2| |badge3| |badge4| |badge5|
@@ -212,7 +208,7 @@ Bug Tracker
212208
Bugs are tracked on `GitHub Issues <https://github.com/OCA/server-tools/issues>`_.
213209
In case of trouble, please check there if your issue has already been reported.
214210
If you spotted it first, help us to smash it by providing a detailed and welcomed
215-
`feedback <https://github.com/OCA/server-tools/issues/new?body=module:%20field_vector%0Aversion:%2016.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
211+
`feedback <https://github.com/OCA/server-tools/issues/new?body=module:%20field_vector%0Aversion:%2018.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
216212

217213
Do not contact contributors directly about support or help with technical issues.
218214

@@ -257,6 +253,6 @@ Current `maintainer <https://odoo-community.org/page/maintainer-role>`__:
257253

258254
|maintainer-lmignon|
259255

260-
This module is part of the `OCA/server-tools <https://github.com/OCA/server-tools/tree/16.0/field_vector>`_ project on GitHub.
256+
This module is part of the `OCA/server-tools <https://github.com/OCA/server-tools/tree/18.0/field_vector>`_ project on GitHub.
261257

262258
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

field_vector/__manifest__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
{
55
"name": "Field Vector",
66
"summary": """New specialized field to store vector data""",
7-
"version": "16.0.1.0.0",
7+
"version": "18.0.1.0.0",
88
"license": "LGPL-3",
99
"author": "ACSONE SA/NV,Odoo Community Association (OCA)",
1010
"website": "https://github.com/OCA/server-tools",

field_vector/fields.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class VectorValue:
2424
"""
2525

2626
def __init__(self, value: list | tuple | np.ndarray, dimensions=None, autopad=True):
27-
if not isinstance(value, (list, tuple, np.ndarray)):
27+
if not isinstance(value, list | tuple | np.ndarray):
2828
raise ValueError(
2929
f"Invalid type '{type(value)}' for VectorValue: "
3030
"Only list, tuple or np.ndarray are allowed."
@@ -124,9 +124,9 @@ class Vector(fields.Field):
124124

125125
def __init__(
126126
self,
127-
dimensions=fields.Default,
128-
autopad=fields.Default,
129-
string=fields.Default,
127+
dimensions=fields.SENTINEL,
128+
autopad=fields.SENTINEL,
129+
string=fields.SENTINEL,
130130
**kwargs,
131131
):
132132
super().__init__(
@@ -136,7 +136,7 @@ def __init__(
136136
def _setup_attrs(self, model_class, name):
137137
res = super()._setup_attrs(model_class, name)
138138
if (
139-
self.dimensions == fields.Default
139+
self.dimensions == fields.SENTINEL
140140
or self.dimensions is None
141141
or not isinstance(self.dimensions, int)
142142
):
@@ -179,7 +179,7 @@ def convert_to_export(self, value: VectorValue, record):
179179
def convert_to_cache(self, value, record, validate=True):
180180
if value is None or value is False:
181181
return None
182-
if not isinstance(value, (list, tuple, np.ndarray, VectorValue)):
182+
if not isinstance(value, list | tuple | np.ndarray | VectorValue):
183183
raise ValueError(
184184
f"Invalid type '{type(value)}' for {self.name}: "
185185
"Only np.ndarray or list of floats/int are allowed."
@@ -190,14 +190,15 @@ def convert_to_cache(self, value, record, validate=True):
190190
value = value.pad(self.dimensions)
191191
if validate and value.dimensions != self.dimensions:
192192
raise ValueError(
193-
f"Invalid vector size for {self.name}: {value.dimensions} != {self.dimensions}"
193+
f"Invalid vector size for {self.name}: "
194+
f"{value.dimensions} != {self.dimensions}"
194195
)
195196
return value
196197

197198
def convert_to_record(self, value, record):
198199
if value is None or value is False:
199200
return None
200-
if not isinstance(value, (list, tuple, np.ndarray, VectorValue)):
201+
if not isinstance(value, list | tuple | np.ndarray | VectorValue):
201202
raise ValueError(
202203
f"Invalid type '{type(value)}' for {self.name}: "
203204
"Only np.ndarray, list of floats/int or VectorValue are allowed."

field_vector/hooks.py

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
from odoo.exceptions import MissingError
66

77

8-
def pre_init_hook(cr):
8+
def pre_init_hook(env):
99
"""setup vector"""
10-
cr.execute(
10+
env.cr.execute(
1111
"""
1212
SELECT
1313
tablename
@@ -17,24 +17,23 @@ def pre_init_hook(cr):
1717
tablename='spatial_ref_sys';
1818
"""
1919
)
20-
check = cr.fetchone()
20+
check = env.cr.fetchone()
2121
if check:
2222
return {}
2323
try:
24-
cr.execute(
24+
env.cr.execute(
2525
"""
2626
CREATE EXTENSION IF NOT EXISTS vector;
2727
"""
2828
)
29-
except Exception as exc:
30-
raise MissingError(
31-
_(
32-
"Error, can not automatically initialize vector"
33-
" support. Database user may have to be superuser and"
34-
" pgvector extensions to be installed. If you do not"
35-
" want Odoo to connect with a super user you can manually"
36-
" prepare your database. To dothis, open a client to your"
37-
" database using a super user and run:\n"
38-
"CREATE EXTENSION vector;\n"
39-
)
40-
) from exc
29+
except Exception:
30+
import logging
31+
32+
_logger = logging.getLogger(__name__)
33+
_logger.warning(
34+
"Could not automatically initialize pgvector support. "
35+
"Database user may need superuser privileges and pgvector "
36+
"extension must be installed. To manually prepare your "
37+
"database, run as superuser:\n"
38+
"CREATE EXTENSION vector;"
39+
)

field_vector/pyproject.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[build-system]
2+
requires = ["whool"]
3+
build-backend = "whool.buildapi"

field_vector/static/description/index.html

Lines changed: 24 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,15 @@
33
<head>
44
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
55
<meta name="generator" content="Docutils: https://docutils.sourceforge.io/" />
6-
<title>README.rst</title>
6+
<title>Field Vector</title>
77
<style type="text/css">
88

99
/*
1010
:Author: David Goodger (goodger@python.org)
11-
:Id: $Id: html4css1.css 9511 2024-01-13 09:50:07Z milde $
11+
:Id: $Id: html4css1.css 8954 2022-01-20 10:10:25Z milde $
1212
:Copyright: This stylesheet has been placed in the public domain.
1313
1414
Default cascading style sheet for the HTML output of Docutils.
15-
Despite the name, some widely supported CSS2 features are used.
1615
1716
See https://docutils.sourceforge.io/docs/howto/html-stylesheets.html for how to
1817
customize this style sheet.
@@ -275,7 +274,7 @@
275274
margin-left: 2em ;
276275
margin-right: 2em }
277276

278-
pre.code .ln { color: gray; } /* line numbers */
277+
pre.code .ln { color: grey; } /* line numbers */
279278
pre.code, code { background-color: #eeeeee }
280279
pre.code .comment, code .comment { color: #5C6576 }
281280
pre.code .keyword, code .keyword { color: #3B0D06; font-weight: bold }
@@ -301,7 +300,7 @@
301300
span.pre {
302301
white-space: pre }
303302

304-
span.problematic, pre.problematic {
303+
span.problematic {
305304
color: red }
306305

307306
span.section-subtitle {
@@ -360,21 +359,16 @@
360359
</style>
361360
</head>
362361
<body>
363-
<div class="document">
362+
<div class="document" id="field-vector">
363+
<h1 class="title">Field Vector</h1>
364364

365-
366-
<a class="reference external image-reference" href="https://odoo-community.org/get-involved?utm_source=readme">
367-
<img alt="Odoo Community Association" src="https://odoo-community.org/readme-banner-image" />
368-
</a>
369-
<div class="section" id="field-vector">
370-
<h1>Field Vector</h1>
371365
<!-- !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
372366
!! This file is generated by oca-gen-addon-readme !!
373367
!! changes will be overwritten. !!
374368
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
375369
!! source digest: sha256:9545962191ec37e88fe11fd9d6e8c01b540134dad5a6482b6a0c19110c7fd3f4
376370
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
377-
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/lgpl-3.0-standalone.html"><img alt="License: LGPL-3" src="https://img.shields.io/badge/license-LGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/server-tools/tree/16.0/field_vector"><img alt="OCA/server-tools" src="https://img.shields.io/badge/github-OCA%2Fserver--tools-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/server-tools-16-0/server-tools-16-0-field_vector"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/server-tools&amp;target_branch=16.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
371+
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/lgpl-3.0-standalone.html"><img alt="License: LGPL-3" src="https://img.shields.io/badge/licence-LGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/server-tools/tree/18.0/field_vector"><img alt="OCA/server-tools" src="https://img.shields.io/badge/github-OCA%2Fserver--tools-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/server-tools-18-0/server-tools-18-0-field_vector"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/server-tools&amp;target_branch=18.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
378372
<p>This addon provides a new field type called “Vector” that allows you to
379373
store and manage vector into your Odoo database.</p>
380374
<p><strong>Table of contents</strong></p>
@@ -401,7 +395,7 @@ <h1>Field Vector</h1>
401395
</ul>
402396
</div>
403397
<div class="section" id="use-cases-context">
404-
<h2><a class="toc-backref" href="#toc-entry-1">Use Cases / Context</a></h2>
398+
<h1><a class="toc-backref" href="#toc-entry-1">Use Cases / Context</a></h1>
405399
<p>The advent of large language models (LLMs) has highlighted the
406400
importance of vector representation as a powerful representation of data
407401
to easily determine the similarity between different pieces of
@@ -410,13 +404,13 @@ <h2><a class="toc-backref" href="#toc-entry-1">Use Cases / Context</a></h2>
410404
allows for efficient similarity comparisons.</p>
411405
</div>
412406
<div class="section" id="installation">
413-
<h2><a class="toc-backref" href="#toc-entry-2">Installation</a></h2>
407+
<h1><a class="toc-backref" href="#toc-entry-2">Installation</a></h1>
414408
<p>To install this module, you need to ensure that the
415409
<a class="reference external" href="https://github.com/pgvector/pgvector">pgvector</a> extension is
416410
installed and available in your PostgreSQL instance.</p>
417411
</div>
418412
<div class="section" id="configuration">
419-
<h2><a class="toc-backref" href="#toc-entry-3">Configuration</a></h2>
413+
<h1><a class="toc-backref" href="#toc-entry-3">Configuration</a></h1>
420414
<p>[ This file is not always required; it should explain <strong>how to configure
421415
the module before using it</strong>; it is aimed at users with administration
422416
privileges.</p>
@@ -431,7 +425,7 @@ <h2><a class="toc-backref" href="#toc-entry-3">Configuration</a></h2>
431425
</ul>
432426
</div>
433427
<div class="section" id="usage">
434-
<h2><a class="toc-backref" href="#toc-entry-4">Usage</a></h2>
428+
<h1><a class="toc-backref" href="#toc-entry-4">Usage</a></h1>
435429
<blockquote>
436430
<div class="line-block">
437431
<div class="line"><strong>⚠️ Warning</strong></div>
@@ -447,7 +441,7 @@ <h2><a class="toc-backref" href="#toc-entry-4">Usage</a></h2>
447441
manage vector data in their Odoo database when they develop their own
448442
modules.</p>
449443
<div class="section" id="field-declaration">
450-
<h3><a class="toc-backref" href="#toc-entry-5">Field declaration</a></h3>
444+
<h2><a class="toc-backref" href="#toc-entry-5">Field declaration</a></h2>
451445
<p>To declare a field of type vector, you can use the following syntax:</p>
452446
<pre class="code python literal-block">
453447
<span class="kn">from</span><span class="w"> </span><span class="nn">odoo.addons.field_vector.fields</span><span class="w"> </span><span class="kn">import</span> <span class="n">Vector</span><span class="w">
@@ -485,7 +479,7 @@ <h3><a class="toc-backref" href="#toc-entry-5">Field declaration</a></h3>
485479
error will be raised.</p>
486480
</div>
487481
<div class="section" id="field-usage">
488-
<h3><a class="toc-backref" href="#toc-entry-6">Field usage</a></h3>
482+
<h2><a class="toc-backref" href="#toc-entry-6">Field usage</a></h2>
489483
<p>The vector field can be used like any other field in Odoo. When
490484
accessing the field, it will always return an
491485
<tt class="docutils literal">odoo.addons.field_vector.fields.VectorValue</tt> object, which is a
@@ -518,7 +512,7 @@ <h3><a class="toc-backref" href="#toc-entry-6">Field usage</a></h3>
518512
</pre>
519513
</div>
520514
<div class="section" id="plain-sql-queries">
521-
<h3><a class="toc-backref" href="#toc-entry-7">Plain SQL queries</a></h3>
515+
<h2><a class="toc-backref" href="#toc-entry-7">Plain SQL queries</a></h2>
522516
<p>When reading the field in plain SQL queries, the field will be returned
523517
as a <tt class="docutils literal">VectorValue</tt> object. You can use the <tt class="docutils literal">value</tt> property to get
524518
the value of the vector as a numpy array.</p>
@@ -539,58 +533,55 @@ <h3><a class="toc-backref" href="#toc-entry-7">Plain SQL queries</a></h3>
539533
</div>
540534
</div>
541535
<div class="section" id="known-issues-roadmap">
542-
<h2><a class="toc-backref" href="#toc-entry-8">Known issues / Roadmap</a></h2>
536+
<h1><a class="toc-backref" href="#toc-entry-8">Known issues / Roadmap</a></h1>
543537
<ul class="simple">
544538
<li>allows the use of specific operators into domain filters to search for
545539
similar vectors.</li>
546540
<li>dedicated widget to display the vector in a more user-friendly way.</li>
547541
</ul>
548542
</div>
549543
<div class="section" id="bug-tracker">
550-
<h2><a class="toc-backref" href="#toc-entry-9">Bug Tracker</a></h2>
544+
<h1><a class="toc-backref" href="#toc-entry-9">Bug Tracker</a></h1>
551545
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/server-tools/issues">GitHub Issues</a>.
552546
In case of trouble, please check there if your issue has already been reported.
553547
If you spotted it first, help us to smash it by providing a detailed and welcomed
554-
<a class="reference external" href="https://github.com/OCA/server-tools/issues/new?body=module:%20field_vector%0Aversion:%2016.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
548+
<a class="reference external" href="https://github.com/OCA/server-tools/issues/new?body=module:%20field_vector%0Aversion:%2018.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
555549
<p>Do not contact contributors directly about support or help with technical issues.</p>
556550
</div>
557551
<div class="section" id="credits">
558-
<h2><a class="toc-backref" href="#toc-entry-10">Credits</a></h2>
552+
<h1><a class="toc-backref" href="#toc-entry-10">Credits</a></h1>
559553
<div class="section" id="authors">
560-
<h3><a class="toc-backref" href="#toc-entry-11">Authors</a></h3>
554+
<h2><a class="toc-backref" href="#toc-entry-11">Authors</a></h2>
561555
<ul class="simple">
562556
<li>ACSONE SA/NV</li>
563557
</ul>
564558
</div>
565559
<div class="section" id="contributors">
566-
<h3><a class="toc-backref" href="#toc-entry-12">Contributors</a></h3>
560+
<h2><a class="toc-backref" href="#toc-entry-12">Contributors</a></h2>
567561
<ul class="simple">
568562
<li>Laurent Mignon <a class="reference external" href="mailto:laurent.mignon&#64;acsone.eu">laurent.mignon&#64;acsone.eu</a> (<a class="reference external" href="https://www.acsone.eu">https://www.acsone.eu</a>)</li>
569563
</ul>
570564
</div>
571565
<div class="section" id="other-credits">
572-
<h3><a class="toc-backref" href="#toc-entry-13">Other credits</a></h3>
566+
<h2><a class="toc-backref" href="#toc-entry-13">Other credits</a></h2>
573567
<p>The development of this module has been financially supported by:</p>
574568
<ul class="simple">
575569
<li><a class="reference external" href="https://www.alcyonbelux.be/">Alcyon Belux</a></li>
576570
</ul>
577571
</div>
578572
<div class="section" id="maintainers">
579-
<h3><a class="toc-backref" href="#toc-entry-14">Maintainers</a></h3>
573+
<h2><a class="toc-backref" href="#toc-entry-14">Maintainers</a></h2>
580574
<p>This module is maintained by the OCA.</p>
581-
<a class="reference external image-reference" href="https://odoo-community.org">
582-
<img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" />
583-
</a>
575+
<a class="reference external image-reference" href="https://odoo-community.org"><img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" /></a>
584576
<p>OCA, or the Odoo Community Association, is a nonprofit organization whose
585577
mission is to support the collaborative development of Odoo features and
586578
promote its widespread use.</p>
587579
<p>Current <a class="reference external" href="https://odoo-community.org/page/maintainer-role">maintainer</a>:</p>
588580
<p><a class="reference external image-reference" href="https://github.com/lmignon"><img alt="lmignon" src="https://github.com/lmignon.png?size=40px" /></a></p>
589-
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/server-tools/tree/16.0/field_vector">OCA/server-tools</a> project on GitHub.</p>
581+
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/server-tools/tree/18.0/field_vector">OCA/server-tools</a> project on GitHub.</p>
590582
<p>You are welcome to contribute. To learn how please visit <a class="reference external" href="https://odoo-community.org/page/Contribute">https://odoo-community.org/page/Contribute</a>.</p>
591583
</div>
592584
</div>
593585
</div>
594-
</div>
595586
</body>
596587
</html>

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# generated from manifests external_dependencies
22
cryptography
33
dataclasses
4+
numpy
45
odoo_test_helper
56
odoorpc
67
openpyxl

0 commit comments

Comments
 (0)