๐Custom scanners
[DRAFT: WORK IN PROGRESS]
[DRAFT: WORK IN PROGRESS] This section is a work in progress and should not be considered complete or comprehensive.
You can extend the functionality of Vigil by creating and implementing your own scanner
module.
High-level concepts
A scanner performs some type of analysis on text data (prompts and responses) and updates the results list for that data.
Scanners can also access the vector database and embedding functions, as well as be passed options from a Vigil configuration file.
ScanModel
Scanners are passed text data in the form of a ScanModel
and can perform analysis on the prompt, prompt_response,
or both.
Once the task is completed, the scanner should update the ScanModel.results
list and return the updated ScanModel
.
BaseScanner
Scanners must subclass the BaseScanner
.
A scanner must implement an analyze()
function that accepts a ScanModel
and UUID.
The post_init
function is also available, which is called as a post-initialization hook after a scanner is created. This can be used for any additional steps required to prep the environment for the scanner, such as loading signatures or updating a database.
The UUID represents the scan action within Vigil dispatch and can be used in log messages or other tracking.
Registry
Vigil dynamically loads scanners that are properly registered using the Registration.scanner
decorator.
Scanners must import the Registration
class and decorate their classes as seen below.
requires_config
This argument specifies whether the scanner requires any configuration options from the Vigil config file (that you passed to Vigil.from_config
.
If set to True
, Vigil will look in that config file for a section named scanner:$name
and pass any key:value options in that section to the registered scanner as keyword arguments.
Config example
requires_embedding
This argument determines if the scanner has access to the Embedder()
class from vigil/core/embedding.py
. The Embedder class is initialized when Vigil.from_config()
is called and provides the ability to generate text embeddings using the model specified in the config file.
In the example below, the Embedder class is passed to the scanner as the embedder
Callable.
requires_vectordb
This argument determines if the scanner has access to the VectorDB
class and its functions:
add_texts(texts: List[str], metadatas: List[dict])
add_embeddings(texts: List[str], embeddings: List[List], metadatas: List[dict])
query(text: str)
Last updated