Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes 4005: Add a procedure for RAG #455

Closed
wants to merge 7 commits into from
Closed

Fixes 4005: Add a procedure for RAG #455

wants to merge 7 commits into from

Conversation

vga91
Copy link
Owner

@vga91 vga91 commented Apr 29, 2024

Fixes https://github.com/neo4j-contrib/neo4j-apoc-procedures/issues/4005

Added a procedure for RAG you pass the user question plus a graph pattern (paths) and relevant attributes and it creates a prompt to answer the user question using the data on those paths and executes that with the llm provider and returns the answer

Retrieval-augmented generation (RAG) is a technique that reduces hallucinations and enhances the accuracy and reliability of generative AI models with facts fetched from external sources.
See here: https://aws.amazon.com/it/what-is/retrieval-augmented-generation/

Changes

  • Created apoc.ml.rag(paths, attributes, question, conf) procedure
  • paths can be a list of paths to retrieve and augment the prompt, it can also be a matching query or a vector index name
  • attributes is the list of relevant attributes useful to retrieve and augment the prompt
  • question is the user question
  • conf can have
    • getLabelTypes (to add label/rel names to the useful info),
    • embeddings to retrieve entities from vector node/rel indexes
    • topK to retrieve k result in case of vector index search
    • prompt to customize the base prompt to be augmented with the context
    • apiKey

TODO

  • Update docs with something like the below one, i.e. to add examples to interface with vector db, when the issue https://github.com/neo4j-contrib/neo4j-apoc-procedures/issues/3971 will be merged
call apoc.vectordb.chroma.query(...) YIELD node 
collect(node) as paths
with paths
call apoc.ml.rag(paths, ...etc) 
...

@vga91 vga91 marked this pull request as draft April 29, 2024 13:31
@vga91 vga91 force-pushed the issue-4005 branch 3 times, most recently from a84095f to ecbc228 Compare April 29, 2024 20:57
@vga91 vga91 changed the title WIP - Fixes 4005: Add a procedure for RAG Fixes 4005: Add a procedure for RAG May 14, 2024
@vga91 vga91 marked this pull request as ready for review May 15, 2024 08:03
@vga91 vga91 marked this pull request as draft May 15, 2024 08:55
@vga91 vga91 marked this pull request as ready for review May 15, 2024 15:21
@RobertoSannino
Copy link
Collaborator

LGTM

@vga91 vga91 closed this May 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants