Open-Assistant icon indicating copy to clipboard operation
Open-Assistant copied to clipboard

Compute text-embeddings for incoming meassges via HF feature-extraction pipeline

Open andreaskoepf opened this issue 2 years ago • 6 comments

We want to store an embedding together with each message in the DB to measure similarity and diversity (e.g. to detect (near-)duplicates).

  1. Select a model to use for the embedding-calculation e.g. see https://huggingface.co/models?pipeline_tag=feature-extraction&sort=downloads (MiniLM & LaBSE were mentioned in internal discussions), potentially discuss with ML-Team on discord, a multilingual model would be preferred, in doubt choose a popular one
  2. Find way to store the embedding vector as postgres array via SQLModel (maybe like shown here?) and add a new (nullable) <short_modelname>_embedding column to store the embedding of message-text, create alembic update script
  3. Use the HuggingFaceAPI class to make an asycn web call for each incoming message and store the embedding in the db. in case of an exception store NULL in the embedding field (successfully store the message anyway).
  4. Create a new debug-flag in the backend settings class (default False) that allows to disable the embedding-calculations. Se the env-variable to True in the scripts/backend_development/run-local.sh script.

(Non-collaborators: Please leave a comment if you want to work on this task. Someone will then assign the task to you.)

andreaskoepf avatar Jan 07 '23 22:01 andreaskoepf

I would take a look at this!

Would it make sense to save the embeddings in a new table? My thinking is that with a new table with the columns message_id, model_name & embedding we could simply store multiple embeddings and experiment with different models.

jojopirker avatar Jan 08 '23 09:01 jojopirker

I think I could also take a look at this one, as it is related to classification of the messages in HF.

nil-andreu avatar Jan 08 '23 10:01 nil-andreu

I would take a look at this!

Would it make sense to save the embeddings in a new table? My thinking is that with a new table with the columns message_id, model_name & embedding we could simply store multiple embeddings and experiment with different models.

Having a new table would make sense to me to minimise schema changes on new models

olliestanley avatar Jan 08 '23 11:01 olliestanley

@SummerSigh see this issue. Similar to embedders we are building for safety. Let's all keep in contact re this so we can cross use stuff @jojopirker.

huu4ontocord avatar Jan 08 '23 18:01 huu4ontocord

I'll ping you guys in the discord channel :) @ontocord

jojopirker avatar Jan 08 '23 18:01 jojopirker

@ontocord Ok! Sounds good!

SummerSigh avatar Jan 08 '23 20:01 SummerSigh

if I understand correctly, this was solved in #540

yk avatar Jan 10 '23 20:01 yk