Interface RAGService
-
- All Known Implementing Classes:
RAGServiceImpl
public interface RAGService
Basic services for retrieval augmented generation (RAG).
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description List<org.apache.sling.api.resource.Resource>
orderByEmbedding(String querytext, List<org.apache.sling.api.resource.Resource> resources, org.apache.sling.api.SlingHttpServletRequest request, org.apache.sling.api.SlingHttpServletResponse response, org.apache.sling.api.resource.Resource rootResource)
Finds the resources whose markdown approximation has embeddings that are the most similar to the querytext embedding.String
ragAnswer(String querytext, List<org.apache.sling.api.resource.Resource> resources, org.apache.sling.api.SlingHttpServletRequest request, org.apache.sling.api.SlingHttpServletResponse response, @NotNull org.apache.sling.api.resource.Resource rootResource, int limitRagTexts)
Answer a question with RAG from the given resources, e.g.List<String>
searchRelated(org.apache.sling.api.resource.Resource root, String querytext, int limit)
Returns a list of up to limit paths that might be related to the query.
-
-
-
Method Detail
-
searchRelated
@Nonnull List<String> searchRelated(@Nullable org.apache.sling.api.resource.Resource root, @Nullable String querytext, int limit) throws javax.jcr.RepositoryException
Returns a list of up to limit paths that might be related to the query. We search for the whole query, andy quoted strings inside and then for all single words in the query, scored. The paths are returned in descending order of lucene score.- Parameters:
root
- the root resource to search inquerytext
- the query textlimit
- the maximum number of paths to return- Returns:
- a list of paths to jcr:content nodes, empty if no results or any of the parameters don't fit.
- Throws:
javax.jcr.RepositoryException
-
orderByEmbedding
@Nonnull List<org.apache.sling.api.resource.Resource> orderByEmbedding(@Nullable String querytext, @Nonnull List<org.apache.sling.api.resource.Resource> resources, @Nonnull org.apache.sling.api.SlingHttpServletRequest request, @Nonnull org.apache.sling.api.SlingHttpServletResponse response, @Nonnull org.apache.sling.api.resource.Resource rootResource) throws javax.jcr.RepositoryException
Finds the resources whose markdown approximation has embeddings that are the most similar to the querytext embedding. Useable e.g. as filter aftersearchRelated(Resource, String, int)
.- Parameters:
querytext
- the query textresources
- the list of resources to search inrequest
- the request to use when determining the markdown approximation - not modifiedresponse
- the response to use when determining the markdown approximation - not modifiedrootResource
- the root resource to search in- Throws:
javax.jcr.RepositoryException
-
ragAnswer
@Nonnull String ragAnswer(@Nullable String querytext, @Nonnull List<org.apache.sling.api.resource.Resource> resources, @Nonnull org.apache.sling.api.SlingHttpServletRequest request, @Nonnull org.apache.sling.api.SlingHttpServletResponse response, @NotNull @NotNull org.apache.sling.api.resource.Resource rootResource, int limitRagTexts)
Answer a question with RAG from the given resources, e.g. found withsearchRelated(Resource, String, int)
.- Parameters:
querytext
- the query textresources
- the list of resources to answer fromrequest
- the request to use when determining the markdown approximation - not modifiedresponse
- the response to use when determining the markdown approximation - not modifiedrootResource
- the root resource to find GPT configuration fromlimitRagTexts
- the maximum number of RAG texts to consider- Returns:
- the answer text
-
-