Skip to main content

knowledge Command

The knowledge commands list, build and search the knowledge bases that agent_actions.yml declares under knowledge:. An action searches a knowledge base with context_scope.retrieve. See Knowledge Bases and Retrieval.

bash
BASH
agac knowledge list
agac knowledge build [NAME] [options]
agac knowledge search NAME TEXT [options]

Each command reads the knowledge: section of agent_actions.yml and checks it as a run does. A problem in a base stops the command, and the error names the base and the key. A NAME that is not a base stops the command, and the error lists the bases.

knowledge list​

Print each knowledge base, its sources, its indexes and whether each index is built:

bash
BASH
agac knowledge list
text
TXT
help_center: 3 source(s), index: keyword, fuzzy
14 file(s), 120 database row(s)
keyword: 9c1f0e2a7b3d4c55 (built)
fuzzy: 41d8a6e0c2b7f913 (not built)

The command reads the source files to compute the digest of each index. It also reads the workflows: when a retrieve entry of a workflow uses the method key, the command shows the key index of that base too. It builds nothing and connects to no database. It counts the rows of a database source from its snapshot. For a base that the command cannot read, it prints not built: and the reason. Then it continues with the next base. A database source with no snapshot gives this result, because the command does not connect to the database.

The command takes no options.

knowledge build​

Build the indexes of each knowledge base, or of the base NAME:

bash
BASH
agac knowledge build
agac knowledge build help_center
agac knowledge build help_center --refresh --prune
text
TXT
help_center keyword: 9c1f0e2a7b3d4c55 (up to date)
help_center fuzzy: 41d8a6e0c2b7f913 (built)

The command builds an index only when no index file holds the digest of the current sources. Otherwise it prints up to date. It writes each index to a temporary file and renames the file, under a lock for the project. Thus a run that starts at the same time waits for the build, and reads a complete index.

The first build of a database source reads its rows and keeps them as a snapshot. A later build reads the snapshot, not the database.

Options​

OptionDescription
NAMEThe knowledge base to build. Default: each base
--refreshRead the query of each database source again, and replace its snapshot. This is the only command that reads the query of an existing snapshot again: agac run --refresh-input does not
--pruneAfter the build, remove the index files of earlier digests. It keeps the current file of each index kind that the base declares or that a retrieve entry uses, key included. Refused while a run of the project is in progress, and when a workflow of the project does not load (the index kinds it searches are not known)

The index files are in .agac/knowledge/<base>/. Old files stay until --prune removes them. If you change a source back before a prune, the next build or run finds the old file again and builds nothing. The command builds each index that the base declares, and the key index when a retrieve entry of a workflow uses the method key. If a workflow does not load, the command writes its name to stderr (Not read (does not load): ...). It still builds the other indexes. knowledge list gives the same note.

Search the knowledge base NAME for TEXT, as a retrieve entry does:

bash
BASH
agac knowledge search help_center "charged twice"
agac knowledge search help_center "pasword reset" --method fuzzy -k 3
agac knowledge search help_center "charged twice" --method keyword --method fuzzy --json
text
TXT
query: "charged" OR "twice" index: 9c1f0e2a7b3d4c55 count: 2
1. knowledge/help_center/billing/duplicate-charges.md#1 score 7.4210 Billing > Duplicate charges
Billing > Duplicate charges If you see two charges for one invoice, the first charge is often a pending authorization...
2. A-204 score 3.1187 Refund timelines
Refund timelines A refund goes back to the card that paid the invoice...

The command builds a missing or old index first, as a run does. It prints the compiled query, the index digest and the count, then one entry for each match: the rank, the id, the score, the title and the first 160 characters of the text.

Options​

OptionDescription
NAMEThe knowledge base to search (required)
TEXTThe query text (required). Quote it when it holds spaces
-k NThe number of matches, from 1 to 50. Default: 5
--method MA search method: keyword, all_words, phrase, fuzzy or key. Give it more than one time to merge methods with equal weights. Default: keyword. The base must have the index of each method. key needs id: on each source, and you cannot merge it with another method
--jsonPrint the output as JSON, in the shape that a retrieve step stores: matches, count, query and index

The command takes no where and no limits other than -k. To test those, run the workflow and read the step with agac records:

bash
BASH
agac records -w support_desk -A write_reply__help

See Also​