Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

esnible
Copy link
Member

@esnible esnible commented Feb 14, 2025

This is a RAG example that uses the correct lifecycle and the Milvus vector database.

Questions. I need feedback before merging.

  • @hirzel Is it OK to remove your old example? Or should we have both?
  • I'm not sure if docs/assets/pdl_quick_reference.pdf is the best example PDF to demo, as it has few sentences.
  • I was not able to get stop_sequences respected. How would a user debug that?
  • This logs many "LiteLLM:WARNING: logging_utils.py:113 - logging_obj not found - unable to track `llm_api_duration_ms". I am not sure if these are my fault.
  • I wanted to see the retrieved sentences. I think Nick's debugger had this, but it was hard to see, so I wrote PDL code to print them. Is there a better way?
  • @starpit The args don't show on function blocks in the debugger, but should. The def name doesn't show on the call, but should. It may be better to show it as a repl rather than as Markdown.

@esnible esnible requested a review from vazirim February 14, 2025 20:02
@hirzel
Copy link
Member

hirzel commented Feb 14, 2025

Is it OK to remove your old example? Or should we have both?

We could rename the old example to "tfidf_rag" or something like that. And then, we can use the name "rag" for your new example, to indicate that it is now the main official RAG example.

Copy link
Collaborator

@mandel mandel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice example!

When trying to execute the program, I had a few dependency missing. I had to do:

 pip install pymilvus pypdf 

You could also say in the readme which models to install with ollama.

And here are some suggestions on how to rewrite pdf_index.pdl:

# Load PDF document into vector database

description: Load document into vector database
lastOf:
- include: rag_library1.pdl
- defs:
    input_data:
      call: ${ pdf_parse }
      args:
        filename: "docs/assets/pdl_quick_reference.pdf"
        chunk_size: 400
        chunk_overlap: 100  
  call: ${ rag_index }
  args:
    inp: ${ input_data }
    encoder_model: "ollama/mxbai-embed-large"
    embed_dimension: 1024
    database_name: "./pdl-rag-demo.db"
    collection_name: "pdl_rag_collection"
- "Success!"

and pdf_query.pdl:

# Query vector database for relevant passages; use passages to query LLM.

defs:
  QUESTIONS:
    data: [
      "Does PDL have a contribute keyword?",
      "Is Brooklyn the capital of New York?"
    ]
lastOf:
  - include: rag_library1.pdl
  - defs:
      CONCLUSIONS:
        for:
          question: ${ QUESTIONS }
        repeat:
            # Define MATCHING_PASSAGES as the text retrieved from the vector DB
          defs:
            MATCHING_PASSAGES:
              call: ${ rag_retrieve }
              args:
                # I am passing the client in implicitly.  NOT WHAT I WANT
                inp: ${ question }
                encoder_model: "ollama/mxbai-embed-large"
                limit: 3
                collection_name: "pdl_rag_collection"  
                database_name: "./pdl-rag-demo.db"
            # debug:
            #   lang: python
            #   code: |
            #      print(f"MATCHING_PASSAGES='{MATCHING_PASSAGES}'")
            #      result = None
            CONCLUSION:
              model: ollama/granite-code:8b
              input: >
                Here is some information:
                ${ MATCHING_PASSAGES }
                Question: ${ question }
                Answer:
              parameters:
                # I couldn't get this working
                stop_sequences: ['Yes', 'No']
                temperature: 0
            ANSWER:
              lang: python
              code: |
                # split()[0] needed because of stop_sequences not working
                # print(f"CONCLUSION={CONCLUSION}")
                result = CONCLUSION.split()[0]
          data:
            ${question}: ${ANSWER}
        join:
          as: array
    text: "${ CONCLUSIONS | tojson }\n"

Copy link
Member

@vazirim vazirim left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Example looks great! See comments.

Langchain provides different types of retrievers with a unified interface. Do the abstractions here reflect that unified interface?
https://python.langchain.com/docs/concepts/retrievers/

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To make the model stop, use stop instead of stop_sequences

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we keep both RAG examples? It would be good for the README to reflect that.

Signed-off-by: Ed Snible <[email protected]>
Signed-off-by: Ed Snible <[email protected]>
Signed-off-by: Ed Snible <[email protected]>
Signed-off-by: Ed Snible <[email protected]>
Copy link
Member

@vazirim vazirim left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@esnible esnible merged commit 8964dd5 into IBM:main Feb 24, 2025
6 checks passed
@esnible esnible deleted the newrag branch February 24, 2025 21:33
jgchn pushed a commit to jgchn/prompt-declaration-language that referenced this pull request Feb 25, 2025
* New RAG example
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants