Failure to insert into collection in Milvus 2.4+ with float32 instead of floatvector data passed

Created on 12 August 2024, about 1 month ago
Updated 18 September 2024, 2 days ago

Exception: Failed to create collection: in Drupal\vdb_provider_milvus\Plugin\VdbProvider\MilvusProvider->insertIntoCollection() (line 221 of /var/www/html/drupal/web/modules/contrib/ai/modules/vdb_providers/vdb_provider_milvus/src/Plugin/VdbProvider/MilvusProvider.php).

I docker-compose up the Milvus as this. When indexing items on page /admin/config/search/search-api/index/[milvus_index_machine_name], it showed error messages: Couldn't index items. Check the logs for details.
The detailed log is:

#0 /var/www/html/drupal/web/modules/contrib/ai/modules/ai_search/src/Plugin/search_api/backend/SearchApiAiSearchBackend.php(358): Drupal\vdb_provider_milvus\Plugin\VdbProvider\MilvusProvider->insertIntoCollection()
#1 /var/www/html/drupal/web/modules/contrib/search_api/src/Entity/Server.php(350): Drupal\ai_search\Plugin\search_api\backend\SearchApiAiSearchBackend->indexItems()
#2 /var/www/html/drupal/web/modules/contrib/search_api/src/Entity/Index.php(1008): Drupal\search_api\Entity\Server->indexItems()
#3 /var/www/html/drupal/web/modules/contrib/search_api/src/Entity/Index.php(937): Drupal\search_api\Entity\Index->indexSpecificItems()
#4 /var/www/html/drupal/web/modules/contrib/search_api/src/IndexBatchHelper.php(160): Drupal\search_api\Entity\Index->indexItems()
#5 /var/www/html/drupal/web/core/includes/batch.inc(296): Drupal\search_api\IndexBatchHelper::process()
#6 /var/www/html/drupal/web/core/includes/batch.inc(138): _batch_process()
#7 /var/www/html/drupal/web/core/includes/batch.inc(94): _batch_do()
#8 /var/www/html/drupal/web/core/modules/system/src/Controller/BatchController.php(52): _batch_page()
#9 [internal function]: Drupal\system\Controller\BatchController->batchPage()
#10 /var/www/html/drupal/web/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(123): call_user_func_array()
#11 /var/www/html/drupal/web/core/lib/Drupal/Core/Render/Renderer.php(638): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}()
#12 /var/www/html/drupal/web/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(121): Drupal\Core\Render\Renderer->executeInRenderContext()
#13 /var/www/html/drupal/web/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(97): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext()
#14 /var/www/html/drupal/vendor/symfony/http-kernel/HttpKernel.php(181): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}()
#15 /var/www/html/drupal/vendor/symfony/http-kernel/HttpKernel.php(76): Symfony\Component\HttpKernel\HttpKernel->handleRaw()
#16 /var/www/html/drupal/web/core/lib/Drupal/Core/StackMiddleware/Session.php(53): Symfony\Component\HttpKernel\HttpKernel->handle()
#17 /var/www/html/drupal/web/core/lib/Drupal/Core/StackMiddleware/KernelPreHandle.php(48): Drupal\Core\StackMiddleware\Session->handle()
#18 /var/www/html/drupal/web/core/lib/Drupal/Core/StackMiddleware/ContentLength.php(28): Drupal\Core\StackMiddleware\KernelPreHandle->handle()
#19 /var/www/html/drupal/web/core/modules/big_pipe/src/StackMiddleware/ContentLength.php(32): Drupal\Core\StackMiddleware\ContentLength->handle()
#20 /var/www/html/drupal/web/core/modules/page_cache/src/StackMiddleware/PageCache.php(106): Drupal\big_pipe\StackMiddleware\ContentLength->handle()
#21 /var/www/html/drupal/web/core/modules/page_cache/src/StackMiddleware/PageCache.php(85): Drupal\page_cache\StackMiddleware\PageCache->pass()
#22 /var/www/html/drupal/web/core/lib/Drupal/Core/StackMiddleware/ReverseProxyMiddleware.php(48): Drupal\page_cache\StackMiddleware\PageCache->handle()
#23 /var/www/html/drupal/web/core/lib/Drupal/Core/StackMiddleware/NegotiationMiddleware.php(51): Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle()
#24 /var/www/html/drupal/web/core/lib/Drupal/Core/StackMiddleware/AjaxPageState.php(36): Drupal\Core\StackMiddleware\NegotiationMiddleware->handle()
#25 /var/www/html/drupal/web/core/lib/Drupal/Core/StackMiddleware/StackedHttpKernel.php(51): Drupal\Core\StackMiddleware\AjaxPageState->handle()
#26 /var/www/html/drupal/web/core/lib/Drupal/Core/DrupalKernel.php(741): Drupal\Core\StackMiddleware\StackedHttpKernel->handle()
#27 /var/www/html/drupal/web/index.php(19): Drupal\Core\DrupalKernel->handle()
#28 {main}

I add dpm($response) before line 221, it showed error as below:

array:2 [
  "code" => 1804
  "message" => "fail to deal the insert data, error: []float32 size 4096 doesn't equal to vector dimension 1536 of FloatVector"
]

Even I use devel module to modify('cause I cannot change via the config UI) the dimensions to 4096 on page /devel/config/edit/search_api.server.milvus and clear cache, the error still exists.

Drupal 10.3, PHP 8.2, ollama Llama3.1:latest model for embeddings, cl100k_base for tokenizer.

🐛 Bug report
Status

Postponed: needs info

Version

1.0

Component

AI Search

Created by

🇨🇳China fishfree

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @fishfree
  • 🇨🇳China fishfree

    Edit: I modfied 3 lines according to the latest ollama version doc. Two are in modules/providers/provider_ollama/src/OllamaControlApi.php:
    - $result = json_decode($this->makeRequest("api/embeddings", [], 'POST', [
    + $result = json_decode($this->makeRequest("api/embed", [], 'POST', [
    - 'prompt' => $text,
    + 'input' => $text,
    'model' => $model,

    The third is in modules/providers/provider_ollama/src/Plugin/AiProvider/OllamaProvider.php:
    - return new EmbeddingsOutput($response['embedding'], $response, []);
    + return new EmbeddingsOutput($response['embeddings'], $response, []);

    Then when manually reindexing, the dpm($responses) error became:

    array:2 [
      "code" => 1804
      "message" => "fail to deal the insert data, error: json: cannot unmarshal array into Go value of type float32: invalid parameter[expected=FloatVector][actual=[[0.0069164913,0.0021438673,0.0065403455,-0.010024414,-0.029039439,0.011868233,-0.010923676,-0.02207415,0.041467343,0.007120738,-0.0134363435,0.0057169143,-0.00522319,-0.012688429,-0.0006849033,0.001478981,-0.0077171754,0.0057560704,-0.008850065,-0.02613559,-0.003200364,0.01103785,0.0059372904,-0.0032610951,-0.024189495,-0.008861378,0.03072281,0.0066399244,-0.02408238,0.0027452302,-0.0149833355,-0.0038356576,0.009427903,0.0028704233,0.0067922943,0.0052720155,......,-0.01320299]]]"
    ]
  • 🇩🇪Germany Marcus_Johansson

    The last problem looks like its because the array is not given back correctly, the first one is because the vector size differs from database and the embeddings engine. To reset it, you will need to remove and recreate the database/index, most vector stores does not allow you to resize this, since you would need to rerun the embeddings engine.

    When you use Ollama or LM Studio we do not get the information back about vector size per each model, so you will have to figure it out and set this correctly yourself when settings it up.

    One solution to this is that it does an actual query and count the vectors before showing the default number per model. This might be slow, but this is the second support request on the same issue and we need to find a way to set this even on providers that can't give that data back.

  • 🇨🇳China fishfree

    @Marcus Yes, I did delete database/index end even reinstalled the ai_search and vdb_provider_milvus modules. The error still exists. I could not change the dimension when creating or editing a Milvus search api server as the screenshot below:

    So I had to edit it to 4096 with devel config editor. I really counted an embedding dimension using curl command.

    However, the error ""fail to deal the insert data, error: json: cannot unmarshal array into Go value of type float32: invalid parameter[expected=FloatVector]" I cannot figure it out why.

    Do you have some working ollama ai_search configurations to share pls?

  • 🇩🇪Germany Marcus_Johansson

    Ah, sorry, I should check versions - if you try to get the DEV version you should have the possibility to set this manually.

  • 🇨🇳China fishfree

    @marcus_johansson The dimension field is editable now, but it shows up still as 768 when re-editing. The more serious problem is the embedding data type incompatibility with Milvus 2.4+ version as mentioned above.

  • 🇬🇧United Kingdom scott_euser

    Can you compare a working query that inserts data into Mvua 2.4? Or a working query that inserts data into an earlier version if not. E.g. Are there scenarios where data does get inserted so we can compare the json?

    Seems issue summary could use an update with the problem as I think you've solved what's described there and are now encountering a new problem it seems.

  • 🇨🇳China fishfree

    @scott_euser Thank you! I remember I succeeded with Milvus 2.3 using search_api_ai 2 months ago.

  • Status changed to Fixed 18 days ago
  • 🇬🇧United Kingdom scott_euser

    I believe this is related to 🐛 Vector dimension mismatch when using Zilliz Fixed and sorted in that fix. Please re-open if still an issue (after you resave your related settings and still experience the issue).

  • 🇨🇳China fishfree

    @scott_euser Thank you! I installed the latest dev version, however, the error still exists. I also changed to try with ollama:phi3 of which the embedding dimension is 3072, but no luck.

  • 🇬🇧United Kingdom scott_euser

    Re-opening as per message from @fishfree

  • Status changed to Active 10 days ago
  • 🇬🇧United Kingdom scott_euser

    Active since no WIP

  • 🇩🇪Germany Marcus_Johansson

    So I could not replicate this and would need more information from the logs or plain requests to your Ollama instance or some other information on how to replicate this.

    What I have tested is:
    1. Get latest dev.
    2. Setup Ollama with phi3:mini
    3. Setup AI Search with Milvus 2.4 locally hosted
    4. Create an index with the dimension 3072.
    5. Indexed one article succesfully.
    6. Try to search for it using the AI API Explorer and it works (see screenshots)

  • Status changed to Postponed: needs info 5 days ago
  • 🇬🇧United Kingdom scott_euser

    Same here, just figured its about time I try out Ollama, so from fresh install in Ubuntu, I tested this out with ollama:mxbai-embed-large, set the dimensions in search api > my index to 3072, and was able to index fine into the Milvus DDEV local.

  • 🇨🇳China fishfree

    @marcus_johansson @scott_euser Thank you, Marcus and Scott!
    What are the versions of your ollama? Mine is 0.3.10.

Production build 0.71.5 2024