Skip to content

Conversation

MateuszOssGit
Copy link
Collaborator

@MateuszOssGit MateuszOssGit commented Oct 17, 2024

Added WatsonxRerank integration:

  • WatsonxRerank init:

    wx_client = APIClient(
        credentials={
            "url": URL,
            "apikey": WX_APIKEY,
        }
    )
    wx_rerank = WatsonxRerank(
        model_id=MODEL_ID, project_id=WX_PROJECT_ID, watsonx_client=wx_client
    )
    
    # OR
    
    wx_rerank = WatsonxRerank(model_id=MODEL_ID, url=URL, apikey=WX_APIKEY, project_id=WX_PROJECT_ID)
  • WatsonxRerank call:

    • rerank() method
     test_documents = [
          Document(page_content="This is a test document."),
          Document(page_content="Another test document."),
      ]
      test_query = "Test query"
      results = wx_rerank.rerank(test_documents, test_query)
    • compress_documents() method
      doc_list = [
          "The Mediterranean diet emphasizes fish, olive oil, and vegetables"
          ", believed to reduce chronic diseases.",
          "Photosynthesis in plants converts light energy into glucose and "
          "produces essential oxygen.",
          "20th-century innovations, from radios to smartphones, centered "
          "on electronic advancements.",
          "Rivers provide water, irrigation, and habitat for aquatic species, "
          "vital for ecosystems.",
          "Apple’s conference call to discuss fourth fiscal quarter results and "
          "business updates is scheduled for Thursday, November 2, 2023 at 2:00 "
          "p.m. PT / 5:00 p.m. ET.",
          "Shakespeare's works, like 'Hamlet' and 'A Midsummer Night's Dream,' "
          "endure in literature.",
      ]
      documents = [Document(page_content=x) for x in doc_list]
    
      result = wx_rerank.compress_documents(
          query="When is the Apple's conference call scheduled?", documents=documents
      )

Updated logic of passing params:

  • params in init:
    When user pass params in init every call using provided params, except case when user pass params in method
  • params in method:
    When user pass params in method they are used, params from init are not used

@MateuszOssGit MateuszOssGit changed the title feat: Added WatsonxRerank integration feat: Added WatsonxRerank integration, update logic of passing params Oct 17, 2024
Copy link
Collaborator

@Wojciech-Rebisz Wojciech-Rebisz left a comment

Choose a reason for hiding this comment

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

Nicely done!

@MateuszOssGit MateuszOssGit merged commit a605c74 into main Oct 29, 2024
12 checks passed
@MateuszOssGit MateuszOssGit deleted the dev-added-rerank branch August 28, 2025 12:45
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.

2 participants