LLM Index API (BETA)
| APIs needed for the knowledge index in the LLM Application. |
| Type | JAR |
| Category | API |
| Developed by | Matéo Munoz, Ludovic Dubost, Michael Hamann, Paul Pantiru |
| Rating | |
| License | GNU Lesser General Public License 2.1 |
Table of contents
Description
This extension provides both Java and REST APIs for the Index for the LLM Application and implements the indexing of the stored content in Solr.
REST API
See the LLM Index REST API documentation.
Custom Authorization Checks
The authorization system in the LLM application that checks in a query if a user can access a document (see also the documentation on authorization in the index) is designed to be fully extensible. To implement a custom authorization method, a component of type org.xwiki.contrib.llm.authorization.AuthorizationManagerBuilder needs to be implemented. If the authorization method needs any configuration, three additional parts need to be implemented:
- A class to store the configuration that is serializable and unserializable using Jackson. This class is mainly used to represent the configuration in the REST API for collections.
- An XClass to store the configuration in the wiki page of the collection
- A sheet to display the aforementioned XClass
The following shows an example component implemented in Groovy that can be used with the Script Component Extension:
package org.xwiki.contrib.llm.internal;
import javax.inject.Named
import javax.inject.Singleton
import org.xwiki.component.annotation.Component
import org.xwiki.contrib.llm.authorization.AuthorizationManager
import org.xwiki.contrib.llm.authorization.AuthorizationManagerBuilder
import org.xwiki.contrib.llm.Collection
import org.xwiki.model.reference.EntityReference
import com.xpn.xwiki.objects.BaseObject
import org.xwiki.model.reference.LocalDocumentReference
/**
* A custom {@link AuthorizationManagerBuilder} that always returns true for all document ids.
*
* @version $Id$
* @since 0.3
*/
@Component
@Named("custom")
@Singleton
class CustomAuthorizationManagerBuilder implements AuthorizationManagerBuilder {
static class ConfigurationType {
String property
ConfigurationType(String property) {
this.property = property
}
}
@Override
AuthorizationManager build(BaseObject configurationObject) {
return { documentIds ->
documentIds.collectEntries { id -> [id, true] }
}
}
@Override
EntityReference getConfigurationClassReference() {
return new LocalDocumentReference('Custom Right Check', 'Class')
}
@Override
EntityReference getConfigurationSheetReference() {
return new LocalDocumentReference('Custom Right Check', 'Sheet')
}
@Override
Class getConfigurationType() {
return ConfigurationType.class
}
@Override
Object getConfiguration(BaseObject object) {
return new ConfigurationType(object.getStringValue("property"))
}
@Override
void setConfiguration(BaseObject object, Object configuration) {
object.setStringValue("property", configuration.property)
}
}This code assume an XClass Custom Right Check.Class with a string property "property" and a sheet Custom Right Check.Sheet to display this property.
The sheet should contribute one or several dt and dd elements that are displayed in the configuration of the collection. A possible sheet would be the following.
{{velocity}}
#set ($object = $doc.getObject('Custom Right Check.Class', true))
#set ($editing = $xcontext.action == 'edit')
#set ($discard = $doc.use($object))
{{html clean="false"}}<dt #if (!$editing && $hasEdit)
class="editableProperty"
data-property="$escapetool.xml($services.model.serialize($object.getPropertyReference('property')))"
data-object-policy="updateOrCreate"
data-property-type="object"#end>
<label#if ($editing) for="Custom Right Check.Class_0_property"#end>
$escapetool.xml($doc.displayPrettyName('property', false, false))
</label>
</dt>
{{/html}}
{{html clean="false"}}<dd>{{/html}}
$doc.display('property')
{{html clean="false"}}</dd>{{/html}}
{{/velocity}}It is important to use the updateOrCreate object policy as there is no separate code for adding the object. Further, this sheet will be applied also on documents that don't contain the configuration object yet, so it is important that the sheet creates it (first line of the code). This sheet is then dynamically loaded when the respective right check method is selected. When another value is selected, the sheet could be hidden again. The sheet thus shouldn't assume that when it is used it is also visible. In case any validation shall be performed, the sheet should verify that it is actually visible before performing any validation.
Prerequisites & Installation Instructions
We recommend using the Extension Manager to install this extension (Make sure that the text "Installable with the Extension Manager" is displayed at the top right location on this page to know if this extension can be installed with the Extension Manager).
You can also use the manual method which involves dropping the JAR file and all its dependencies into the WEB-INF/lib folder and restarting XWiki.
Versions
Dependencies
Dependencies for this extension (org.xwiki.contrib.llm:application-ai-llm-index-api 0.8):
- org.xwiki.commons:xwiki-commons-script 17.4.4
- org.xwiki.platform:xwiki-platform-rest-api 17.4.4
- org.xwiki.platform:xwiki-platform-rest-server 17.4.4
- org.xwiki.platform:xwiki-platform-livedata-api 17.4.4
- org.xwiki.platform:xwiki-platform-search-solr-query 17.4.4
- org.xwiki.platform:xwiki-platform-security-authorization-api 17.4.4
- org.xwiki.platform:xwiki-platform-user-api 17.4.4
- org.xwiki.contrib.llm:application-ai-llm-models-api 0.8
- io.github.resilience4j:resilience4j-retry 2.2.0