Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
72 commits
Select commit Hold shift + click to select a range
91bf334
updates.md French
arnaud4d Jun 5, 2026
52449d7
updates.md Spanish
arnaud4d Jun 5, 2026
a5f9b03
updates.md Japanese
arnaud4d Jun 5, 2026
12f0a0f
updates.md Portuguese, Brazilian
arnaud4d Jun 5, 2026
9f5bd0d
dataclassclass.md French
arnaud4d Jun 5, 2026
83292b8
dataclassclass.md French
arnaud4d Jun 5, 2026
93a13ae
dataclassclass.md Spanish
arnaud4d Jun 5, 2026
fccbefe
dataclassclass.md Spanish
arnaud4d Jun 5, 2026
b9edb03
dataclassclass.md Japanese
arnaud4d Jun 5, 2026
65d4421
dataclassclass.md Japanese
arnaud4d Jun 5, 2026
467d5ee
dataclassclass.md Portuguese, Brazilian
arnaud4d Jun 5, 2026
1b61049
dataclassclass.md Portuguese, Brazilian
arnaud4d Jun 5, 2026
e435fb6
writeprointerface.md French
arnaud4d Jun 5, 2026
ac99839
user-new.md French
arnaud4d Jun 5, 2026
c368c0c
wp-multi-level-list-button.png French
arnaud4d Jun 5, 2026
d28423f
wp-multi-level-list-button1.png French
arnaud4d Jun 5, 2026
019b7f3
wp-multi-level-list-button2.png French
arnaud4d Jun 5, 2026
3492a27
wp-multi-level-list-button3.png French
arnaud4d Jun 5, 2026
6b04c86
wp-multi-level-list-button4.png French
arnaud4d Jun 5, 2026
00ee830
wp-multi-level-list-button5.png French
arnaud4d Jun 5, 2026
97df57b
wp-multi-level-list-button6.png French
arnaud4d Jun 5, 2026
d5aa076
wp-multi-level-list-button8.png French
arnaud4d Jun 5, 2026
efdff01
wp-multi-level-list-panel.png French
arnaud4d Jun 5, 2026
d192d99
wp-multi-level-list-panel2.png French
arnaud4d Jun 5, 2026
5037498
wp-multi-level-list-stylesheets1.png French
arnaud4d Jun 5, 2026
1d0f99a
wp-multi-level-list-stylesheets2.png French
arnaud4d Jun 5, 2026
7841c1e
wp-multi-level-list7.png French
arnaud4d Jun 5, 2026
eff2d7a
writeprointerface.md Spanish
arnaud4d Jun 5, 2026
694d897
user-new.md Spanish
arnaud4d Jun 5, 2026
8feb0e7
wp-multi-level-list-button.png Spanish
arnaud4d Jun 5, 2026
fb4ff70
wp-multi-level-list-button1.png Spanish
arnaud4d Jun 5, 2026
1b9c811
wp-multi-level-list-button2.png Spanish
arnaud4d Jun 5, 2026
a1686c2
wp-multi-level-list-button3.png Spanish
arnaud4d Jun 5, 2026
83382a0
wp-multi-level-list-button4.png Spanish
arnaud4d Jun 5, 2026
2962c21
wp-multi-level-list-button5.png Spanish
arnaud4d Jun 5, 2026
7c2a60c
wp-multi-level-list-button6.png Spanish
arnaud4d Jun 5, 2026
341a862
wp-multi-level-list-button8.png Spanish
arnaud4d Jun 5, 2026
f4ec9cc
wp-multi-level-list-panel.png Spanish
arnaud4d Jun 5, 2026
88bcb60
wp-multi-level-list-panel2.png Spanish
arnaud4d Jun 5, 2026
c20f244
wp-multi-level-list-stylesheets1.png Spanish
arnaud4d Jun 5, 2026
22b577c
wp-multi-level-list-stylesheets2.png Spanish
arnaud4d Jun 5, 2026
52250e3
wp-multi-level-list7.png Spanish
arnaud4d Jun 5, 2026
3f36358
writeprointerface.md Japanese
arnaud4d Jun 5, 2026
72afb48
user-new.md Japanese
arnaud4d Jun 5, 2026
0d521f4
wp-multi-level-list-button.png Japanese
arnaud4d Jun 5, 2026
7411a67
wp-multi-level-list-button1.png Japanese
arnaud4d Jun 5, 2026
093b86d
wp-multi-level-list-button2.png Japanese
arnaud4d Jun 5, 2026
73688ee
wp-multi-level-list-button3.png Japanese
arnaud4d Jun 5, 2026
dddec5c
wp-multi-level-list-button4.png Japanese
arnaud4d Jun 5, 2026
06a9156
wp-multi-level-list-button5.png Japanese
arnaud4d Jun 5, 2026
bac3356
wp-multi-level-list-button6.png Japanese
arnaud4d Jun 5, 2026
494040a
wp-multi-level-list-button8.png Japanese
arnaud4d Jun 5, 2026
cbc5ced
wp-multi-level-list-panel.png Japanese
arnaud4d Jun 5, 2026
1a15a7c
wp-multi-level-list-panel2.png Japanese
arnaud4d Jun 5, 2026
aa67e07
wp-multi-level-list-stylesheets1.png Japanese
arnaud4d Jun 5, 2026
e0598f1
wp-multi-level-list-stylesheets2.png Japanese
arnaud4d Jun 5, 2026
4bb15d9
wp-multi-level-list7.png Japanese
arnaud4d Jun 5, 2026
b357692
writeprointerface.md Portuguese, Brazilian
arnaud4d Jun 5, 2026
5fd0396
user-new.md Portuguese, Brazilian
arnaud4d Jun 5, 2026
26d3918
wp-multi-level-list-button.png Portuguese, Brazilian
arnaud4d Jun 5, 2026
2434c9f
wp-multi-level-list-button1.png Portuguese, Brazilian
arnaud4d Jun 5, 2026
e506dcf
wp-multi-level-list-button2.png Portuguese, Brazilian
arnaud4d Jun 5, 2026
f784fd3
wp-multi-level-list-button3.png Portuguese, Brazilian
arnaud4d Jun 5, 2026
0045569
wp-multi-level-list-button4.png Portuguese, Brazilian
arnaud4d Jun 5, 2026
a5443b9
wp-multi-level-list-button5.png Portuguese, Brazilian
arnaud4d Jun 5, 2026
19f4592
wp-multi-level-list-button6.png Portuguese, Brazilian
arnaud4d Jun 5, 2026
99a0902
wp-multi-level-list-button8.png Portuguese, Brazilian
arnaud4d Jun 5, 2026
3f3c0ff
wp-multi-level-list-panel.png Portuguese, Brazilian
arnaud4d Jun 5, 2026
70ac077
wp-multi-level-list-panel2.png Portuguese, Brazilian
arnaud4d Jun 5, 2026
aab0ef4
wp-multi-level-list-stylesheets1.png Portuguese, Brazilian
arnaud4d Jun 5, 2026
f494ffd
wp-multi-level-list-stylesheets2.png Portuguese, Brazilian
arnaud4d Jun 5, 2026
e4390e1
wp-multi-level-list7.png Portuguese, Brazilian
arnaud4d Jun 5, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1222,11 +1222,11 @@ Si *attributePath* designa un atributo que almacena [**objetos vectores**](../AP

En este caso, el parámetro *value* debe ser un **objeto vectorial de comparación** que contenga las siguientes propiedades:

| Propiedad | Tipo | Descripción |
| --------- | -------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| vector | [4D.Vector](../API/VectorClass.md) | Obligatorio. El vector a comparar |
| metric | Text | Opcional. [Cálculo vectorial](../API/VectorClass.md#understanding-the-different-vector-computations) a utilizar para la consulta. Puede utilizar una de las siguientes constantes (Texto)<li>:`mk cosine` (por defecto si se omite): calcula la similaridad en cosenos entre los vectores.</li><li>`mk dot`: calcula la similaridad en puntos de los vectores.</li><li>`mk euclidean`: calcula la distancia euclideana entre vectores. |
| threshold | Real | Opcional (por defecto: 0,5). Un valor umbral utilizado para filtrar las comparaciones de vectores en función de su puntuación de similitud coseno, punto o euclídea según la "métrica" seleccionada. Es altamente recomendable elegir una similitud que se adapte mejor a su caso de uso específico para obtener resultados óptimos. |
| Propiedad | Tipo | Descripción |
| --------- | -------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| vector | [4D.Vector](../API/VectorClass.md) | Obligatorio. El vector a comparar |
| metric | Text | Opcional. [Cálculo vectorial](../API/VectorClass.md#understanding-the-different-vector-computations) a utilizar para la consulta. You can use one of the following (Text) constants:<li>`mk cosine` (default if omitted): calculates the [cosine similarity](./VectorClass.md#cosinesimilarity) between vectors.</li><li>`mk dot`: calculates the [dot similarity](VectorClass.md#dotsimilarity) of vectors.</li><li>`mk euclidean`: calculates the [Euclidean distance](./VectorClass.md#euclideandistance) between vectors. |
| threshold | Real | Opcional (por defecto: 0,5). Un valor umbral utilizado para filtrar las comparaciones de vectores en función de su puntuación de similitud coseno, punto o euclídea según la "métrica" seleccionada. Es altamente recomendable elegir una similitud que se adapte mejor a su caso de uso específico para obtener resultados óptimos. |

Sólo se admite un subconjunto de símbolos **comparadores**. Tenga en cuenta que comparan los resultados con el valor umbral:

Expand All @@ -1241,36 +1241,41 @@ Por ejemplo, se desea devolver entidades de MyClass donde la similaridad con un

```4d
var $myVector : 4D.Vector
$myVector := getVector ///método para obtener un vector, por ejemplo a partir de 4D.AIKit
var $comparisonVector := {vector: $myVector; metric: mk euclidean; threshold: 1.2}
$myVector := getVector //method to get a vector, e.g. from 4D.AIKit
var $comparisonVector := {vector: $myVector; metric: mk cosine; threshold: 1.2}
var $results := ds.MyClass.query("myVectorField <= :1"; $comparisonVector)
```

La instrucción **orden by** es soportada en la cadena de consulta para que las entidades en la selección de entidad resultante estén ordenadas por similitud. Por ejemplo:

```4d
var $results := ds.MyClass.query("myVectorField > :1 order by myVectorField desc"; $comparisonVector)
//the first entity is the most similar
//$results.first() entity is the most similar
```

:::note

The default order is ascending, although a descending order is usually the most useful for vector similarity queries. Thus, you will usually have to add the `desc` keyword in your vector similarity query strings.
You will generally want vector similarity query results to be sorted from "most similar" to "least similar." By default, results returned with an **order by** clause are sorted in ascending order. Depending on the similarity metric used, you may need to adjust the sorting direction to obtain the correct ranking:

- for [**cosine**](./VectorClass.md#cosinesimilarity) and [**dot**](./VectorClass.md#dotsimilarity) similarity, higher values indicate greater similarity. Therefore, you will typically need to include the `desc` keyword in the query string.
- for [**euclidean distance**](./VectorClass.md#euclideandistance) similarity, lower values indicate greater similarity. In this case, the default ascending order (or explicitly using the `asc` keyword) is appropriate.

:::

Si el mismo vector aparece varias veces en la cadena de consulta, el orden por se aplicará a los resultados del primero, por ejemplo:
You can only order on a single vector field. Si el mismo vector aparece varias veces en la cadena de consulta, el orden por se aplicará a los resultados del primero, por ejemplo:

```4d
var $results := ds.MyClass.query("myVectorField > :1 and myVectorField > :2 order by myVectorField desc"; /
{vector : $myVector1 };{vector : $myVector2 }) //myVectorField > :1 is used for the order by
{vector : $myVector1 };{vector : $myVector2 })
//myVectorField > :1 is used for the order by
```

Ver [más ejemplos a continuación](#example-4-2) (ejemplos 4 y 5).

:::tip Entradas de blog relacionadas

- [4D AI: Búsqueda de entidades por similaridad vectorial en 4D](https://blog.4d.com/4d-ai-searching-entities-by-vector-similarity-in-4d)
- [4D AI: Sorting Query Results by Vector Similarity](https://blog.4d.com/4d-ai-sorting-query-results-by-vector-similarity/)
- [Por qué su Pila de búsqueda está rota y cómo lo soluciona la búsqueda vectorial](https://blog.4d.com/why-your-search-stack-feels-broken-and-how-vector-search-fixes-it)

:::
Expand Down Expand Up @@ -1637,31 +1642,29 @@ var $client:=cs.AIKit.OpenAI.new("my api key")
var $result:=$client.embeddings.create("my long text to search"; "text-embedding-ada-002")
var $vector:=$result.vector

//el atributo embedding se basa en un campo 4D que almacena objetos de clase 4D.Vector
//buscar con la métrica por defecto (coseno)
var $employees:=ds.Employee.query("embedding > :1"; {vector : $vector})
//buscar con la métrica euclídea
var $employees:=ds.Employee.query("embedding > :1"; {vector: $vector; metric: mk euclidean})
//búsqueda con métrica coseno explícita y umbral personalizado
var $employees:=ds.Employee.query("embedding > :1"; {vector: $vector; metric: mk cosine; threshold: 0.9})
//buscar con una fórmula
//embedding attribute is based upon a 4D field storing 4D.Vector class objects

//search with default metric (cosine)
var $employees:=ds.Employee.query("embedding > :1 order by embedding desc"; {vector : $vector})

//search with euclidean metric
var $employees:=ds.Employee.query("embedding < :1 order by embedding"; {vector: $vector; metric: mk euclidean})

//search with explicit cosine metric and custom threshold
var $employees:=ds.Employee.query("embedding > :1 order by embedding desc"; {vector: $vector; metric: mk cosine; threshold: 0.9})

//search with a formula
var $employees:=ds.Employee.query(Formula(This.embdedding.cosineSimilarity($vector)>0.9))

```

#### Ejemplo 5

Queremos ejecutar una consulta por similitud vectorial utilizando vectores con diferentes métricas y ordenar los resultados por similaridades de coseno:
Vector-based semantic ordering can be combined with traditional ORDA filters in the same query.

```4d
//Crear los vectores de comparación
var $vector1Comparison:={vector: $myvector; métrica: mk coseno; umbral: 0.4}
var $vector2Comparison:={vector: $myvector; metric: mk euclidean; threshold:1}

//el atributo embedding se basa en un campo 4D que almacena objetos de clase 4D.Vector
ds.VectorTable.query("embedding>:1 and embedding<:2";$vector1Comparison;$vector2Comparison)\
.orderByFormula(Formula(This.embedding.cosineSimilarity($vector1Comparison)))

var $comparisonVector := {vector: $myVector; metric: mk cosine; threshold: 0.4}
var $results := ds.MyTable.query("myVectorField <= :1 AND salary>100000 order by myVectorField, salary desc"; $comparisonVector)
```

#### Ver también
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ Lea [**Novedades en 4D 21 R4**](https://blog.4d.com/whats-new-in-4d-21-r4/), la

#### Lo más destacado

- New [`defer`](../commands/defer) command to declare some code to be always executed at method or function exit.
- Multi-level list style sheets are now [supported in 4D Write Pro Interface](../WritePro/writeprointerface.md#multi-level-style-sheets), allowing users to create and manage structured multi-level lists directly from the toolbar and sidebar.
- New [`defer`](../commands/defer) command to declare some code to be always executed at method or function exit; new [`Deferred formulas`](../commands/deferred-formulas) command to get the list of deferred formulas.

## 4D 21 R3

Expand All @@ -18,7 +19,7 @@ Lea [**Novedades en 4D 21 R3**](https://blog.4d.com/es/whats-new-in-4d-21-r3/),
#### Lo más destacado

- El comando [`JSON Validate`](../commands/json-validate) ahora es compatible con el borrador 2020-12 del esquema JSON.
- 4D Write Pro now supports [hierarchical list style sheets](../WritePro/user-legacy/stylesheets.md#hierarchical-list-style-sheets), enabling the creation and management of structured [multi-level lists](../WritePro/user-legacy/using-a-4d-write-pro-area.md#multi-level-lists) with automatic numbering.
- 4D Write Pro now supports [multi-level list style sheets](../WritePro/user-legacy/stylesheets.md#multi-level-list-style-sheets), enabling the creation and management of structured [multi-level lists](../WritePro/user-legacy/using-a-4d-write-pro-area.md#multi-level-lists) with automatic numbering.
- Ability to use a custom certificate from the macOS keychain instead of a local certificates folder in [`HTTPRequest`](../API/HTTPRequestClass.md#4dhttprequestnew) and [`HTTPAgent`](../API/HTTPAgentClass.md#4dhttpagentnew) classes.
- Nueva clase [`4D.Method`](../API/MethodClass.md) para crear y ejecutar un código de método 4D a partir de una fuente de texto. [`METHOD Get path`](../commands/method-get-path) and [`METHOD RESOLVE PATH`](../commands/method-resolve-path) commands support a new `path volatile method` constant (128).
- IMAP transporter now supports mailbox event notifications using the IDLE protocol through a [notifier object](../API/IMAPTransporterClass.md#notifier) of the [4D.IMAPNotifier](../API/IMAPNotifierClass.md) class, configurable via the `listener` property of [IMAP New transporter](../commands/imap-new-transporter).
Expand Down
Loading
Loading