Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
ai
Manage
Activity
Members
Labels
Plan
Wiki
Custom issue tracker
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
project
ai
Commits
2695f93a
Commit
2695f93a
authored
5 months ago
by
Marcus Johansson
Browse files
Options
Downloads
Patches
Plain Diff
Issue
#3471259
by marcus_johansson: Vector dimension mismatch when using Zilliz
parent
c0c371ec
No related branches found
No related tags found
No related merge requests found
Pipeline
#271599
passed with warnings
5 months ago
Stage: build
Stage: validate
Stage: test
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
modules/ai_search/src/Trait/AiSearchBackendEmbeddingsEngineTrait.php
+45
-14
45 additions, 14 deletions
...search/src/Trait/AiSearchBackendEmbeddingsEngineTrait.php
with
45 additions
and
14 deletions
modules/ai_search/src/Trait/AiSearchBackendEmbeddingsEngineTrait.php
+
45
−
14
View file @
2695f93a
...
...
@@ -4,6 +4,8 @@ namespace Drupal\ai_search\Trait;
use
Drupal\ai\AiProviderInterface
;
use
Drupal\ai\Plugin\ProviderProxy
;
use
Drupal\Core\Ajax\AjaxResponse
;
use
Drupal\Core\Ajax\InvokeCommand
;
use
Drupal\Core\Form\FormStateInterface
;
use
Drupal\Core\Form\SubformStateInterface
;
use
Drupal\Core\StringTranslation\StringTranslationTrait
;
...
...
@@ -33,7 +35,21 @@ trait AiSearchBackendEmbeddingsEngineTrait {
* The configuration.
*/
public
function
setEngineConfiguration
(
array
$configuration
):
void
{
$this
->
engineConfiguration
=
$configuration
;
// Load data.
if
(
isset
(
$configuration
[
'embeddings_engine'
]))
{
$plugin_manager
=
\Drupal
::
service
(
'ai.provider'
);
$parts
=
explode
(
'__'
,
$configuration
[
'embeddings_engine'
]);
$rule
=
$plugin_manager
->
createInstance
(
$parts
[
0
])
->
getAvailableConfiguration
(
'embeddings'
,
$parts
[
1
]);
$this
->
engineConfiguration
=
$configuration
;
foreach
(
$rule
as
$key
=>
$value
)
{
if
(
$key
==
'dimensions'
)
{
$this
->
engineConfiguration
[
'embeddings_engine_configuration'
][
$key
]
=
$value
[
'default'
];
}
}
}
else
{
$this
->
engineConfiguration
=
$configuration
;
}
}
/**
...
...
@@ -69,6 +85,7 @@ trait AiSearchBackendEmbeddingsEngineTrait {
if
(
$form_state
instanceof
SubformStateInterface
)
{
$form_state
=
$form_state
->
getCompleteFormState
();
}
if
(
empty
(
$this
->
engineConfiguration
))
{
$this
->
engineConfiguration
=
$this
->
defaultEngineConfiguration
();
}
...
...
@@ -81,6 +98,8 @@ trait AiSearchBackendEmbeddingsEngineTrait {
'#default_value'
=>
$this
->
getConfiguration
()[
'embeddings_engine'
]
??
$this
->
defaultEngineConfiguration
()[
'embeddings_engine'
],
'#description'
=>
$this
->
t
(
'The service to use for embeddings. If you change this, everything will be needed to be reindexed.'
),
'#weight'
=>
20
,
// If its update, we don't allow to change the embeddings engine.
'#disabled'
=>
!
empty
(
$this
->
engineConfiguration
[
'embeddings_engine'
]),
'#ajax'
=>
[
'callback'
=>
[
$this
,
'updateEmbeddingEngineConfigurationForm'
],
'wrapper'
=>
'embedding-engine-configuration-wrapper'
,
...
...
@@ -103,18 +122,14 @@ trait AiSearchBackendEmbeddingsEngineTrait {
'#description'
=>
$this
->
t
(
'The number of dimensions for the embeddings.'
),
'#default_value'
=>
$this
->
engineConfiguration
[
'embeddings_engine_configuration'
][
'dimensions'
]
??
''
,
'#required'
=>
TRUE
,
// If its update, we don't allow to change the dimensions.
'#disabled'
=>
!
empty
(
$this
->
engineConfiguration
[
'embeddings_engine'
]),
// Load via ajax calls.
'#attributes'
=>
[
'class'
=>
[
'embeddings-engine-configuration-dimensions'
],
],
];
// If the embeddings engine is set, add the configuration form.
if
(
!
empty
(
$this
->
engineConfiguration
[
'embeddings_engine'
])
||
$form_state
->
getValue
(
'embeddings_engine'
))
{
$plugin_manager
=
\Drupal
::
service
(
'ai.provider'
);
$parts
=
explode
(
'__'
,
$this
->
engineConfiguration
[
'embeddings_engine'
]
??
$form_state
->
get
(
'embeddings_engine'
));
$rule
=
$plugin_manager
->
createInstance
(
$parts
[
0
])
->
getAvailableConfiguration
(
'embeddings'
,
$parts
[
1
]);
foreach
(
$rule
as
$key
=>
$value
)
{
$form
[
'embeddings_engine_configuration'
][
$key
][
'#default_value'
]
=
$value
[
'default'
];
}
}
return
$form
;
}
...
...
@@ -170,11 +185,27 @@ trait AiSearchBackendEmbeddingsEngineTrait {
* @param \Drupal\Core\Form\FormStateInterface $form_state
* The form state.
*
* @return array
* @return array
|AjaxResponse
* The updated form.
*/
public
function
updateEmbeddingEngineConfigurationForm
(
array
$form
,
FormStateInterface
$form_state
):
array
{
return
$form
[
'backend_config'
][
'embeddings_engine_configuration'
];
public
function
updateEmbeddingEngineConfigurationForm
(
array
$form
,
FormStateInterface
$form_state
):
array
|
AjaxResponse
{
$plugin_manager
=
\Drupal
::
service
(
'ai.provider'
);
$parts
=
explode
(
'__'
,
$form_state
->
getValue
(
'backend_config'
)[
'embeddings_engine'
]);
if
(
count
(
$parts
)
!==
2
)
{
return
$form
[
'backend_config'
][
'embeddings_engine_configuration'
];
}
// The subform reload doesn't work, so AjaxResponse is needed.
$dimensions
=
$this
->
engineConfiguration
[
'embeddings_engine_configuration'
][
'dimensions'
]
??
768
;
$rule
=
$plugin_manager
->
createInstance
(
$parts
[
0
])
->
getAvailableConfiguration
(
'embeddings'
,
$parts
[
1
]);
foreach
(
$rule
as
$key
=>
$value
)
{
if
(
$key
==
'dimensions'
)
{
$dimensions
=
$value
[
'default'
];
}
}
$response
=
new
AjaxResponse
();
$add_value
=
new
InvokeCommand
(
'.embeddings-engine-configuration-dimensions'
,
'val'
,
[
$dimensions
]);
$response
->
addCommand
(
$add_value
);
return
$response
;
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment