pinecallDocs
Key concepts / Knowledge bases

Knowledge bases

A folder of documents pushed, attached to an agent, and searched before every turn.

A knowledge base is a folder of Markdown documents kept by the gateway. Attach it to an agent, and the platform searches it before every turn and hands the model the chunks that answer the caller.

What is a knowledge base?#

A base has a name and holds Markdown files. Sandbox and production each have their own bases, so a base you push from your laptop is the one your own pinecall start answers from, never the one your phone number answers from.

Your manager adds and edits documents in the console, on the agent's Knowledge ▸ Docs screen, one file at a time. Those edits live in the gateway, not in your repository.

Create one#

Write the documents#

Put Markdown under agents/<agent>/docs/ in your project, one file per subject, with headings. A new project ships a README.md there, which a push never sends: every other *.md in the folder is. The folder is a checkout of the base, committed with the code.

Push them#

Terminal
pinecall docs push

The base takes the agent's name unless --base names another. Add --prod to push production's base. A class that declares its base (@agent({ docs: { base: "clinica-norte" } }), Python's docs, Ruby's docs base:) pushes the folder itself: every Markdown file under agents/<agent>/docs/ is written into that base when the agent registers — on pinecall start, and on a deploy — the base's other files kept, so this step is only for an agent whose base is a setting.

Attach the base to the agent#

Terminal
pinecall docs attach clinica-norte --k 4

From the next call on, every turn searches it.

Hold it to a golden#

Write agents/<agent>/test/goldens/docs.json and run pinecall docs eval. Testing knowledge & memory shows how.

The folder is a checkout of the base: a push writes the files it has and keeps the base's other files, so a document someone added in the console survives it. pinecall docs push --replace makes the base the folder and drops what the folder has not. pinecall docs pull brings the base back into the folder, file by file, and pinecall docs rm <path> removes one file from the base.

What a push does#

  • The files of the folder are written into the base by their paths; the base's other files are kept. With --replace, the base becomes the folder.
  • Each file is cut at its headings (# to ###). A section longer than 350 tokens is cut again at a paragraph or a sentence. A fenced code block is never cut.
  • Each chunk carries its heading path, for example Prices › Check-up, in the text both indexes read. The file's name is not in it.
  • Front matter (a title: / source: block at the top of a file) is dropped, and so is every HTML comment outside a code block: a note to the author never reaches the model.
  • One comment is read. <!-- asks … --> at the top of a section lists the questions it answers, one a line, invisible on any site that renders the file. Each is indexed beside the section in the words a caller would use, and a caller who asks it is handed the section. A question counts as a chunk.
  • Every chunk is indexed twice: by its embedding and by its words. A search asks both and fuses the two rankings.
  • The words are stemmed in the base's language, so supervise finds supervising and sábados finds sábado. pinecall docs push --language en says it (en, es, pt, fr, de, it, nl); left out, it is counted from the files' own words, and a folder that says no language clearly (tables, names) is indexed with no stemming. The push's line says which, and pinecall docs list shows it.
  • A file that did not change since the last push is not embedded again.

A push cannot tell a menu from a paragraph. A scraped page full of navigation and footers competes for the chunks a turn gets and answers nothing, so read what goes into the folder.

An org's chunks count against its knowledge_chunks quota. Limits & provider keys says where to see it.

Attach it to an agent#

attach writes the agent's bases setting as a new version, in sandbox unless you add --prod. A class that declares docs sets this itself: its declaration wins, and attach is refused until the class lets go of it.

flag what it sets default
--k <n> how many chunks a turn is handed 8
--mode retrieved the platform searches before every turn yes
--mode tool the platform does not search before the turn: only the model, when it calls search
--min-score <x> drops chunks scored below x, on a 0 to 1 scale where the best chunk of each search is 1 none
--team writes the team's settings instead of yours

--min-score cuts the tail of an answer. It can never say "nothing here answers this", because the best chunk of any search scores 1. Whether to search at all is decided before the search, on the caller's words.

An agent may read several bases. A turn then searches all of them in one pass, with one ranking over everything, so a base with nothing to say about the question takes none of the turn's chunks. The turn's k is the largest of the attachments; each --min-score applies to its own base.

When a turn searches#

With --mode retrieved, a spoken turn's search starts while the caller is still speaking, once they have said four words, and runs again on the whole turn when it said more; the early answer stands in when the second is late. A turn shorter than four words, and every written turn, is searched when it ends. A turn with no letter in it (a phone number being read out) is never searched.

In either mode the model also holds the search tool whenever a base is attached, and may call it with a query of its own. A spoken turn waits at most 250 ms for the answer and a written one 3 s; a search that is late is dropped, the turn goes on without it, and the log says search_skipped.

Search from a tool#

A tool can search the attached bases itself:

agents/clinica-norte/agent.tsx
/** Looks up what the patient asks in the clinic's documents and returns the paragraphs that answer it. */
@tool()
async lookUp(question: string): Promise<Found[]> {
  return await this.knowledge.search(question, { k: 3 });
}

Each result is { path, heading, text }. A class that uses this.knowledge is refused at registration when no base is attached to it, with the command that fixes it:

clinica-norte searches its bases, and none is attached to it in sandbox: pinecall docs attach <base> --agent clinica-norte

The other verbs#

Terminal
pinecall docs list                 # the bases, their chunks, when each was pushed
pinecall docs attached             # which agents read which base
pinecall docs detach clinica-norte # the agent stops reading it
pinecall docs drop clinica-norte   # the base is deleted

Next steps#