llm-tools / embedJs

A NodeJS RAG framework to easily work with LLMs and embeddings
https://llm-tools.mintlify.app/get-started/introduction
Apache License 2.0
333 stars 40 forks source link

Switching Loaders / Vectors #58

Open converseKarl opened 6 months ago

converseKarl commented 6 months ago

If i need to switch a vector, i can switch dynamically based on the setVector and Path settingss and changing these to different values.

The question is, loaders, for example if i wanted to use a defined loader i used with a vector db, how to retrieve or remember it or reload it back when switching from one to other. I have a listLoaders api i wrote, to return me the list, types and id's but if you reload server, they all go. So it's about persisting without have to call the reloaders again such as re-adding web pages once they are in the vector db/llm cache.

If ti can be managed, this way you can potentially have multiple rags, and even build a graph type llm or a simpler router llm at the front of it later to decide which rag to to switch to.

should there be a loadVector/LoadEmbeddings function?

Any advice is appreciated. I think your doing an awesome job, I will try raise that FAISS PR this weekend!

adhityan commented 6 months ago

Switching vectors is tricky because they need to be initialized. I have been thinking myself also around adding support for multiple RAG sets. One can then set which RAG set to use for which query and can also multiple RAG sets each for a few documents.

However, this complicates the API quiet a bit making it difficult for simpler use cases. Needs more thought this one.

converseKarl commented 6 months ago

Hi there, been thinking too about this, and wanted to share my thoughts and whether this can help and if these scenarios are possible

What I observed today it should be possible to

  1. Create loader intances and track them in memory and switch object of objects or array of objects with a unique rag key
  2. The rag can be switched based on the vector and llm cache on the fly

It's about persistence (i.e. if needed to restart server) and or load the last one that was in use

Is possiblefor the ragbuilder/app instance object state to be somehow stored in some kind of binary o other format, saved to disk, Basically a loader representation no disk

  1. saveLoaderStateToDisk(ragid)
    • saves current state of existing loader updating it
  2. removeLoaderStateFromDisk(ragid)
    • removes loader from disk
  3. switchLoaders(rag id)
    • switches loader from one to other in that current object (if no current loader, simply loads in the specifed loader if exist)
  4. removeAllLoaderStatesFromDisk();
    • removes all stored loaders
  5. getLoaderIntance(rag id) into instance of variable type ragApplication etc (useful for in memory switching) so you could load multiple rags and switch on the go or you could load multiple Rag instances into an object array of rags, This could then be fronted by a LLM router or LLM knowledge Graph to determine which sub rag to use, switch to and query.