KnowledgeBase is a collection of documents used to generate test cases for a domain or task — typically the vector store behind retrieval-augmented generation (RAG).
Documents are grouped by topics. If you do not pass seed_topics, the connector clusters embeddings and names topics with an LLM.
trusttest.knowledge_base only re-exports KnowledgeBase, InMemoryKnowledgeBase, and Document. Azure, Neo4j, Postgres, and Upstash must be imported from their submodules.
Connectors
AzureKnowledgeBase
Import:from trusttest.knowledge_base.azure_search import AzureKnowledgeBase
Leverages Azure AI Search and is best suited for:
- Cloud-based document indexing and storage
- Full-text search with advanced filtering and ranking
- Integration with Microsoft’s AI-powered search stack
Neo4jKnowledgeBase
Import:from trusttest.knowledge_base.neo4j import Neo4jKnowledgeBase
Built on Neo4j, this connector excels at:
- Handling complex document relationships
- Graph-based querying and clustering
- Constructing dynamic knowledge graphs
PgVectorKnowledgeBase
Import:from trusttest.knowledge_base.pgvector import PgVectorKnowledgeBase
Leverages PostgreSQL with pgvector:
- Semantic vector search on your existing Postgres tables
- Configurable
connection_string,table_name, andfields_mapping
UpstashKnowledgeBase
Import:from trusttest.knowledge_base.upstash import UpstashKnowledgeBase
Serverless Upstash Vector store for:
- Managed similarity search without operating a cluster
- URL + token authentication (
UPSTASH_URL/UPSTASH_TOKEN)
InMemoryKnowledgeBase
Import:from trusttest.knowledge_base import InMemoryKnowledgeBase, Document
A minimal, no-dependency implementation designed for:
- Prototyping and local testing
- Lightweight, quick-start environments
- Small-scale document classification
Topic Creation Process
The topic creation pipeline groups unlabeled documents using embeddings, UMAP, HDBSCAN, and an LLM summarizer. It is not Azure-only — any vector connector that embeds documents can run it.This process is triggered when no predefined (
seed_topics) list is provided. Configure embeddings and topic_summarizer with set_config (or pass embeddings_model / llm_client).-
Document Retrieval
- Pulls documents using the mapped
idandcontentfields. - Filters out empty or whitespace-only content.
- Optionally detects language on ingested documents (
trusttest[language-detection]).
- Pulls documents using the mapped
-
Embedding Generation
- Applies an embedding model to each document’s content (truncated to
3 * max_tokens). - Produces high-dimensional semantic vectors for clustering.
- Applies an embedding model to each document’s content (truncated to
-
Dimensionality Reduction
- Uses UMAP to reduce embedding vectors.
n_neighbors,n_components, and initialization scale with document count.
- Uses UMAP to reduce embedding vectors.
-
Topic Clustering
- Runs HDBSCAN over the reduced vectors. Noise and outliers are discarded (
label = -1).
- Runs HDBSCAN over the reduced vectors. Noise and outliers are discarded (
-
LLM-based Topic Naming
- Names each cluster with the
topic_summarizerclient. - Uses up to
max_docssamples per topic, truncated tomax_doc_length.
- Names each cluster with the
-
Return Structure
- A dictionary mapping topic names to documents, plus flat lists of topic names and documents.