Skip to main content
A 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
Azure connector →

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
Neo4j connector →

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, and fields_mapping
PostgreSQL connector →

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)
Upstash connector →

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
In-memory connector →

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).
  1. Document Retrieval
    • Pulls documents using the mapped id and content fields.
    • Filters out empty or whitespace-only content.
    • Optionally detects language on ingested documents (trusttest[language-detection]).
  2. Embedding Generation
    • Applies an embedding model to each document’s content (truncated to 3 * max_tokens).
    • Produces high-dimensional semantic vectors for clustering.
  3. Dimensionality Reduction
    • Uses UMAP to reduce embedding vectors. n_neighbors, n_components, and initialization scale with document count.
  4. Topic Clustering
    • Runs HDBSCAN over the reduced vectors. Noise and outliers are discarded (label = -1).
  5. LLM-based Topic Naming
    • Names each cluster with the topic_summarizer client.
    • Uses up to max_docs samples per topic, truncated to max_doc_length.
  6. Return Structure
    • A dictionary mapping topic names to documents, plus flat lists of topic names and documents.