matrixone icon indicating copy to clipboard operation
matrixone copied to clipboard

LLM_EMBEDDING implementation

Open charleschile opened this issue 1 year ago • 2 comments

What type of PR is this?

  • [ ] API-change
  • [ ] BUG
  • [ ] Improvement
  • [ ] Documentation
  • [x] Feature
  • [ ] Test and CI
  • [ ] Code Refactoring

Which issue(s) this PR fixes:

issue #18664

What this PR does / why we need it:

As part of our document LLM support, we are introducing the LLM_EMBEDDING function. This function can a string or embed the content from a specified txt file by using LLM platforms like Ollama and LLM models like llama3.

Three global variables are introduced for users to customize their own LLM platforms, proxy and models.

Three global variables:

  • llm_embedding_platform: default is ollama
  • llm_server_proxy: default is http://localhost:11434/api/embed
  • llm_model: default is llama3

Usage: llm_embedding(<input txt datalink>); or llm_embedding(<input string>);

Return Value: a vector of 4096 32-bit floating point.

Note:

  • we only support ollama for the platform right now.
  • if you want to use the Llama 3 model, ensure that the model is running by executing ollama run llama3 in the shell before using the embedding function.

Example SQL:

-- datalink
SELECT llm_embedding(cast('file:///Users/charles/Desktop/codes/testData/embeddingTest.txt' as datalink));

-- string
SELECT llm_embedding("This is text... bla ");

Example return:

mysql> SELECT embedding("This is text... bla ");

embedding(This is text... bla )                                                                                                                                                                                                                                |
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
 [-0.021955958, -0.024112409, 0.010994452, -0.011615187, 0.03107838, -0.024938945, -0.029811664, -0.018000955, -0.01751671, -0.0007840055, -0.021467123, -0.014996716, -0.0045815744, -0.026652282, -0.016832603, 0.009745739, -0.016642446, 0.00514828, -0.015859831, -0.010222016, -0.010362088, 0.0056358385, -0.015048031, -0.0031982209, -0.010094931, 0.016682236, 0.008610655, -0.010177104, 0.0035889482, -0.011772896, 0.0020790452, 0.0064958483, 0.007662446, -0.011871371, -0.0060495464, -0.00031009244 |

1 row(s) fetched.

charleschile avatar Sep 01 '24 10:09 charleschile