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

spike: Search support articles via OpenAI embeddings #7162

Closed
wants to merge 8 commits into from

Conversation

sojan-official
Copy link
Member

Changes

  • add vector column using pgvector gem
  • nearest neighbour search using neighbour gem : https://github.com/ankane/neighbor
  • add service to generate, store and search support article embeddings

TODO

  • Pass context to GPT for article suggestions in Chat

Setting up the POC

  • Ensure support for vector extension in your postgres installation: ref: https://github.com/pgvector/pgvector
  • Run migrations in the branch and create appropriate tables
  • Enable OpenAI integration Hook in Chatwoot
  • Load some support articles using the following script or any custom method
    • ## Sample FAQs Generated by GPT
      faqs = [
        { title: "502 bad gateway in nginx server", 
          content: "This issue may arise when trying to install Chatwoot from scratch using Linux in Digital Ocean. The same repository in git and a change in the line that on \"install.sh\" could potentially solve the issue."
        },
        { title: "Configure Litespeed to serve as a frontend proxy for chatwoot or any docker",
          content: "When docker chatwoot is fully activated, there might be a need to convert Litespeed (as part of a Cpanel installation) to a frontend proxy. This requires specific settings to be configured."
        },
        { title: "Error with deploy Chatwoot in Heroku: Free dynos are no longer available", 
          content: "This error might appear even when subscribed to an Eco subscription. It suggests an error in scaling dynos, and might require subscribing to Eco to get the application up and running."
        },
        { title: "send message via chatwoot api - String does not have #dig method", 
          content: "Sending an interactive message via PHP and chatwoot api might cause this issue. Understanding the structure of interactive messages in the Chatwoot API documentation can help resolve this."
        },
        { title: "chatwoot api - create message", 
          content: "Sending a message with the chatwoot api involves following the instructions in the API documentation. If the message isn't sending, the code might need to be debugged or adjusted."
        },
        { title: "chatwoot - welcome message from dialogflow", 
          content: "If using the chatwoot widget, which is connected to dialogflow, you might want to send a dialogflow message when the user writes the first message. If there is no response from the welcome intent, further investigation is needed."
        },
        { title: "Chatwoot - Send attachments - NodeJS", 
          content: "Sending files through the ChatWoot API might present challenges. This often involves using a specific framework and making requests using \"HttpService\"."
        },
        { title: "Rails: Error running rake due to different ruby version", 
          content: "This error can occur when using a self-hosted chatwoot installation on AWS using Ubuntu, especially when upgrading the chatwoot version and precompiling the assets. The issue is often due to Ruby version mismatches."
        },
        { title: "Windows WSL: systemctl restart chatwoot.target not working", 
          content: "After installing chatwoot from the official documentation, you might encounter issues with restarting chatwoot. This is often due to the system not being booted with systemd as init."
        },
        { title: "What is the value proposition of Chatwoot?", 
          content: "Chatwoot has been incredibly helpful for our business. We love how it integrates with our existing tools and they continue to add more features."
        },
        { title: "How does Chatwoot integrate with other platforms?", 
          content: "Chatwoot is a great product. It helps us manage customer conversations from different platforms like WhatsApp, Facebook, Twitter, etc."
        },
        { title: "How frequently does Chatwoot release new features?", 
          content: "We've been using Chatwoot for a while now and they've been adding new features and integrations regularly."
        },
        { title: "Is Chatwoot a good tool for customer support?", 
          content: "Very good tool for customer support. It's great to have all customer queries from different channels all in one place."
        },
        { title: "Can I use Chatwoot for my small business?", 
          content: "I've been using Chatwoot for my small business. It's very helpful and I highly recommend it."
        },
        { title: "How does Chatwoot help in tracking client conversations?", 
          content: "I've been using Chatwoot for a few months now and it's been incredibly helpful to keep track of client conversations."
        },
        { title: "What are the benefits of using Chatwoot for customer support?", 
          content: "Chatwoot is a simple, yet powerful tool. It has made a big difference to our customer support."
        },
        { title: "How does Chatwoot help in managing customer conversations?", 
          content: "Chatwoot is a great tool for managing customer conversations. It's easy to use and has a lot of features."
        },
        { title: "Can I integrate Chatwoot with my existing CRM?", 
          content: "Yes, Chatwoot can be integrated with various CRM platforms to manage and streamline your customer conversations."
        },
        { title: "Is Chatwoot mobile-friendly?", 
          content: "Absolutely, Chatwoot is designed to be responsive and can be used on various devices including mobiles, tablets, and desktops."
        },
        { title: "Does Chatwoot support multi-language?", 
          content: "Yes, Chatwoot is a multilingual platform. It supports multiple languages to help businesses connect with their customers globally."
        },
        { title: "How secure is Chatwoot?", 
          content: "Security is a top priority for Chatwoot. It follows best security practices to ensure the safety and privacy of your customer conversations."
        },
        { title: "What is the pricing for Chatwoot?", 
          content: "Chatwoot offers different pricing tiers based on your business needs. You can check the official Chatwoot website for detailed pricing information."
        },
        { title: "Can I customize Chatwoot for my business?", 
          content: "Yes, Chatwoot offers various customization options to align with your business branding and customer support needs."
        },
        { title: "Does Chatwoot offer analytics?", 
          content: "Yes, Chatwoot offers robust analytics to help you understand your customer interactions better and improve your customer support."
        },
        { title: "Can Chatwoot handle high volume of customer messages?", 
          content: "Chatwoot is designed to handle a high volume of customer messages seamlessly, ensuring that your customer support is efficient and reliable."
        },
        { title: "Does Chatwoot have an API?", 
          content: "Yes, Chatwoot offers a well-documented API that you can use to integrate Chatwoot's functionality into your own applications or workflows."
        },
        { title: "How can I migrate my data to Chatwoot?", 
          content: "Chatwoot provides tools and documentation to help you migrate your data from other platforms, making the transition as smooth as possible."
        }
      ]
      
      
      # load your portal here
      portal = Account.first.portals.first
      # Create articles with sample data
      faqs.each do |faq|
        article = Article.create(title: faq[:title], content: faq[:content], account_id: portal.account.id, portal_id: portal.id, author: portal.account.users.first, status: :published, category: portal.categories.first)
        article.save!
      end
      
  • Generate embeddings for the articles and perform a search to view the results
    • hook = Integrations::Hook.first # Change this accordingly to fetch your openai integration hook
      # generates embeddings for articles in support center
      Integrations::Openai::EmbeddingsService.new(hook: hook).create_article_embeddings
      # Searches the articles and returns the results
      # change hello with your relevant keyword
      Integrations::Openai::EmbeddingsService.new(hook: hook).search_article_embeddings('cost of Chatwoot')
      
      ## map just title and content 
      Integrations::Openai::EmbeddingsService.new(hook: hook).search_article_embeddings('cost of Chatwoot').map{|a| [a.title, a.content[0..100]]}
      

Observations

  • Results of a couple of searches over the embeddings of the sample faq data
Screenshot 2023-05-22 at 8 25 51 PM

- add `vector` column using pgvector gem
- add service to generate, store and search support article embeddings
@netlify
Copy link

netlify bot commented May 22, 2023

Deploy Preview for chatwoot-storybook ready!

Name Link
🔨 Latest commit f26649a
🔍 Latest deploy log https://app.netlify.com/sites/chatwoot-storybook/deploys/64a594b9e2ba0c00072eafa0
😎 Deploy Preview https://deploy-preview-7162--chatwoot-storybook.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@sojan-official
Copy link
Member Author

ref: https://linear.app/chatwoot/issue/CW-1830/feat-suggestion-bot-poc-using-open-ai-embeddings

The POC has been updated to pass context to the bot from article embedding and answer from only that. In other cases, it returns agent handoff.

Screenshot 2023-05-30 at 4 18 39 AM Screenshot 2023-05-30 at 4 19 43 AM

To run the POC

  • Follow the original set up instructions PR description ( set up openai integration/load data and generate embeddings )
  • Create an OpenAI agent bot from the console
bot = Account.first.agent_bots.new
bot.name =  'Woot Bot'
bot.bot_type = :open_ai
bot.save!
  • Associate OpenAI agent bot to the support widget console
inbox = Inbox.first
inbox.agent_bot = bot
inbox.save

Try chatting

@sojan-official
Copy link
Member Author

closing in favor of #7518

@github-actions
Copy link

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 19, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant