Knowledge bases reference v7

Reference for knowledge base (KB) functions and views. For guide-style documentation, see Knowledge bases.

Views

aidb.knowledge_bases

Also accessible as aidb.kbs. Lists all knowledge bases in the database with their full configuration.

ColumnTypeDescription
idintegerInternal identifier
nametextKnowledge base name
vector_schematextSchema of the embeddings table
vector_tabletextEmbeddings storage table
model_nametextEmbedding model used
distance_operatoraidb.DistanceOperatorVector distance function used for retrieval
distance_operator_sqltextThe distance operator in SQL-operator syntax (for example, <->, <=>)
vector_data_columntextEmbeddings column
vector_key_columntextKey column in the embeddings table
vector_indexjsonbVector index configuration
pipeline_idsinteger[]IDs of all pipelines attached to this knowledge base
pipeline_namestext[]Names of all pipelines attached to this knowledge base

aidb.knowledge_base_metrics

Also accessible as aidb.kbm. Aggregated stats for each knowledge base — pipeline count, embedding row count, and the worst pipeline status. For per-pipeline progress (backlog, errors, source / destination counts), see aidb.pipeline_metrics.

ColumnTypeDescription
nametextKnowledge base name (schema.vector_table).
pipelinesintegerNumber of pipelines attached to this KB.
embeddingsbigintRow count of the vector table.
statustextWorst status across all attached pipelines (see aidb.PipelineStatus).

Example

SELECT * FROM aidb.kbm;
Output
             name             | pipelines | embeddings |  status
------------------------------+-----------+------------+----------
 public.product_catalog_kb    |         1 |       1842 | UpToDate
 public.customer_feedback_kb  |         2 |        915 | UpToDate
(2 rows)

The legacy view names aidb.knowledge_base_stats and aidb.kbstat are kept as aliases of aidb.knowledge_base_metrics for backward compatibility.


Types

aidb.DistanceOperator

Vector distance function used during retrieval.

ValueDescription
L2Euclidean distance
InnerProductInner product
CosineCosine similarity
L1L1 distance
HammingHamming distance
JaccardJaccard distance

aidb.PipelineDataFormat

Format of data in a pipeline source or volume.

ValueDescription
TextPlain text
ImageBinary image data
PdfPDF documents

aidb.PipelineAutoProcessingMode

Auto-processing mode for a knowledge base pipeline.

ValueDescription
LiveImmediate processing via Postgres triggers on each data change
BackgroundPeriodic processing via a Postgres background worker
DisabledNo automatic processing; run manually with aidb.run_pipeline()

Knowledge base functions

To change a pipeline's auto-processing mode, use aidb.update_pipeline.

aidb.retrieve_key

Returns the source record keys and distances for the top matching embeddings, without fetching source data. In part_ids also returns the IDs of the matching parts for each step in a multi-step pipeline.. For example, if a single source record is split into 10 parts by a "ChunkText" step, then part_ids indicates which chunk matched.

Parameters

ParameterTypeDefaultDescription
knowledge_base_nameTEXTRequiredName of the knowledge base (schema.vector_table).
queryTEXT or BYTEARequiredQuery text or image bytes. Must match the data format of the embedding model.
topkINTEGER0Number of results to return. 0 uses the default of 1.
deduplicateBOOLEANtrueReturn each source result only once even if multiple "parts" (for example, chunks/pages) match

Returns

ColumnTypeDescription
keytextSource record key
distancedouble precisionVector distance from the query
part_idsbigint[]Which parts (for example, chunk or page) of the source record produced the matching vector
pipeline_nametextName of the pipeline that supplied this row. Useful when the KB has multiple attached pipelines.

Example

SELECT * FROM aidb.retrieve_key('public.customer_feedback_kb', 'late delivery', topk=>3);
Output
 key  |      distance      | part_ids |   pipeline_name
------+--------------------+----------+------------------
 1042 | 1.1931772046185758 | {0,0}    | feedback_eu_pipe
 318  | 1.1980633963685476 | {2,0}    | feedback_na_pipe
 1057 | 1.2150919866080878 | {2,0}    | feedback_eu_pipe
(3 rows)

aidb.retrieve_text

Returns source text and distances for the top matching embeddings by joining the embeddings table with the source table. In part_ids, also returns the IDs of the matching parts for each step in a multi-step pipeline. For example if a single source record is split into 10 parts by a "ChunkText" step, then part_ids will indicate which chunk matched. The return column intermediate_steps contains the actual intermediate step output.

Parameters

ParameterTypeDefaultDescription
knowledge_base_nameTEXTRequiredName of the knowledge base (schema.vector_table).
queryTEXT or BYTEARequiredQuery text or image bytes. Must match the data format of the embedding model.
topkINTEGER0Number of results to return. 0 uses the default of 1.
deduplicateBOOLEANtrueReturn each source result only once even if multiple "parts" (for example, chunks/pages) match

Returns

ColumnTypeDescription
keytextSource record key
valuetextSource text content. NULL when the original source content is non-text (for example, PDF or Image); other columns still surface match metadata.
distancedouble precisionVector distance from the query
part_idsbigint[]Which part of the source record matched (for example, a chunk or page)
pipeline_nametextThe name of the pipeline processing this source record
intermediate_stepsjsonbThe matching results from the intermediate steps; that is, the values belonging to "part_ids"

Example

SELECT * FROM aidb.retrieve_text('my_kb', 'waterproof jacket', 3);
Output
  key  |                       value                        |      distance
-------+----------------------------------------------------+--------------------
 19337 | Men Stripes Waterproof Shell Jacket                | 0.2994317672742334
 55018 | Women All-Weather Hiking Anorak                    | 0.3804609668507203
(2 rows)

aidb.delete_knowledge_base

Cascades: deletes all pipelines attached to the knowledge base, drops the vector table, and removes the registry entry. Does not delete underlying source tables.

To remove a single pipeline from a multi-pipeline KB while keeping the KB and the other pipelines' vectors intact, use aidb.delete_pipeline instead. Deleting the last attached pipeline also drops the KB.

Parameters

ParameterTypeDescription
knowledge_base_nameTEXTKnowledge base identifier (schema.vector_table).

Example

SELECT aidb.delete_knowledge_base('public.customer_feedback_kb');

Volume functions

aidb.create_volume

Creates an AIDB volume from a PGFS storage location. The volume is a foreign table that exposes the storage location's contents as rows and can be used as a knowledge base data source or queried directly with SQL. See External data sources for setting up the PGFS storage location first.

Parameters

ParameterTypeDescription
nameTEXTName for the volume. Must be a valid unquoted PostgreSQL identifier.
server_nameTEXTName of the PGFS storage location.
pathTEXTOptional sub-path within the storage location. Canonicalized to a single trailing slash (for example, foo, /foo, foo/, /foo/ all store as foo/; NULL or / store as /).
data_formatTEXTData format: Text, Image, or Pdf.

Example

SELECT aidb.create_volume('pdf_volume', 'my_s3_location', '/', 'Pdf');

aidb.volumes

View that lists all AIDB volumes in the database. Returns schema, volume, storage_location, and path.

SELECT * FROM aidb.volumes;

aidb.delete_volume

Deletes an AIDB volume.

Note

Deleting the underlying PGFS storage location also deletes all volumes built on top of it.

Parameters

ParameterTypeDescription
volume_nameTEXTName of the volume to delete.
SELECT aidb.delete_volume('pdf_volume');