Class RAGServlet

  • All Implemented Interfaces:
    Serializable, javax.servlet.Servlet, javax.servlet.ServletConfig

    public class RAGServlet
    extends org.apache.sling.api.servlets.SlingSafeMethodsServlet
    Servlet providing various RAG supported services.
    See Also:
    Serialized Form
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected com.google.gson.Gson gson  
      static String PARAM_EMBEDDINGORDER
      Boolean parameter - if true, the results will be ordered by comparing the embedding with the query embedding.
      static String PARAM_LIMIT
      Maximum number of results from the search that are ranked with the embedding.
      static String PARAM_LIMITRAGTEXTS
      For query answering (ragAnswer): the maximum number of pages that are given to the AI to answer.
      static String PARAM_QUERY
      The actual search query.
      protected RAGService ragService  
    • Constructor Summary

      Constructors 
      Constructor Description
      RAGServlet()  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      protected void doGet​(@NotNull org.apache.sling.api.SlingHttpServletRequest request, @NotNull org.apache.sling.api.SlingHttpServletResponse response)  
      protected String ragAnswer​(org.apache.sling.api.resource.ResourceResolver resourceResolver, org.apache.sling.api.resource.Resource searchRoot, String query, int limit, boolean embeddingOrder, org.apache.sling.api.SlingHttpServletRequest request, org.apache.sling.api.SlingHttpServletResponse response, int limitRagTexts)  
      protected List<?> related​(org.apache.sling.api.resource.ResourceResolver resourceResolver, org.apache.sling.api.resource.Resource searchRoot, String query, int limit, boolean embeddingOrder, org.apache.sling.api.SlingHttpServletRequest request, org.apache.sling.api.SlingHttpServletResponse response)
      Does a plain search for the terms, without actual RAG.
      • Methods inherited from class org.apache.sling.api.servlets.SlingSafeMethodsServlet

        doGeneric, doHead, doOptions, doTrace, getAllowedRequestMethods, getServletInfo, handleMethodNotImplemented, mayService, service, service
      • Methods inherited from class javax.servlet.GenericServlet

        destroy, getInitParameter, getInitParameterNames, getServletConfig, getServletContext, getServletName, init, init, log, log
    • Field Detail

      • gson

        protected final com.google.gson.Gson gson
      • PARAM_LIMIT

        public static final String PARAM_LIMIT
        Maximum number of results from the search that are ranked with the embedding. Default is 20.
        See Also:
        Constant Field Values
      • PARAM_LIMITRAGTEXTS

        public static final String PARAM_LIMITRAGTEXTS
        For query answering (ragAnswer): the maximum number of pages that are given to the AI to answer. Default is 5.
        See Also:
        Constant Field Values
      • PARAM_EMBEDDINGORDER

        public static final String PARAM_EMBEDDINGORDER
        Boolean parameter - if true, the results will be ordered by comparing the embedding with the query embedding.
        See Also:
        Constant Field Values
    • Constructor Detail

      • RAGServlet

        public RAGServlet()
    • Method Detail

      • doGet

        protected void doGet​(@NotNull
                             @NotNull org.apache.sling.api.SlingHttpServletRequest request,
                             @NotNull
                             @NotNull org.apache.sling.api.SlingHttpServletResponse response)
                      throws javax.servlet.ServletException,
                             IOException
        Overrides:
        doGet in class org.apache.sling.api.servlets.SlingSafeMethodsServlet
        Throws:
        javax.servlet.ServletException
        IOException
      • related

        protected List<?> related​(@Nonnull
                                  org.apache.sling.api.resource.ResourceResolver resourceResolver,
                                  @Nonnull
                                  org.apache.sling.api.resource.Resource searchRoot,
                                  @Nonnull
                                  String query,
                                  int limit,
                                  boolean embeddingOrder,
                                  org.apache.sling.api.SlingHttpServletRequest request,
                                  org.apache.sling.api.SlingHttpServletResponse response)
                           throws javax.jcr.RepositoryException
        Does a plain search for the terms, without actual RAG. E.g. http://localhost:9090/bin/cpm/ai/rag.related.json/content/ist/composum/home?query=AI
        Throws:
        javax.jcr.RepositoryException
      • ragAnswer

        protected String ragAnswer​(@Nonnull
                                   org.apache.sling.api.resource.ResourceResolver resourceResolver,
                                   @Nonnull
                                   org.apache.sling.api.resource.Resource searchRoot,
                                   @Nonnull
                                   String query,
                                   int limit,
                                   boolean embeddingOrder,
                                   org.apache.sling.api.SlingHttpServletRequest request,
                                   org.apache.sling.api.SlingHttpServletResponse response,
                                   int limitRagTexts)
                            throws javax.jcr.RepositoryException
        Throws:
        javax.jcr.RepositoryException