Class LLMKnowledgeExtractor

java.lang.Object
com.tnsai.session.extraction.LLMKnowledgeExtractor
All Implemented Interfaces:
KnowledgeExtractor

public class LLMKnowledgeExtractor extends Object implements KnowledgeExtractor
LLM-based knowledge extractor.

Uses an LLM to analyze session conversations and extract reusable knowledge like solutions, patterns, and insights.

Usage


 LLMClient llm = new OpenAIClient("gpt-4o-mini", apiKey);
 KnowledgeExtractor extractor = new LLMKnowledgeExtractor(llm);

 List<ExtractedKnowledge> knowledge = extractor.extract(session);

 // Filter high-confidence results
 knowledge.stream()
     .filter(k -> k.isHighConfidence())
     .forEach(k -> System.out.println(k.type() + ": " + k.summary()));
 
Author:
TnsAI Team
  • Constructor Details

    • LLMKnowledgeExtractor

      public LLMKnowledgeExtractor(com.tnsai.llm.LLMClient llmClient)
      Creates an extractor with default settings.
      Parameters:
      llmClient - the LLM client to use for extraction
    • LLMKnowledgeExtractor

      public LLMKnowledgeExtractor(com.tnsai.llm.LLMClient llmClient, double minConfidence)
      Creates an extractor with custom confidence threshold.
      Parameters:
      llmClient - the LLM client to use
      minConfidence - minimum confidence threshold (0.0 to 1.0)
  • Method Details

    • extract

      public List<ExtractedKnowledge> extract(AgentSession session, Set<ExtractionType> types)
      Description copied from interface: KnowledgeExtractor
      Extracts specific types of knowledge from a session.
      Specified by:
      extract in interface KnowledgeExtractor
      Parameters:
      session - the session to extract from
      types - the types of knowledge to extract
      Returns:
      list of extracted knowledge items
    • getMinConfidence

      public double getMinConfidence()
      Description copied from interface: KnowledgeExtractor
      Gets the minimum confidence threshold for extraction. Items below this threshold will not be returned.
      Specified by:
      getMinConfidence in interface KnowledgeExtractor
      Returns:
      minimum confidence (0.0 to 1.0)
    • withMinConfidence

      public KnowledgeExtractor withMinConfidence(double minConfidence)
      Description copied from interface: KnowledgeExtractor
      Creates a new extractor with a different confidence threshold.
      Specified by:
      withMinConfidence in interface KnowledgeExtractor
      Parameters:
      minConfidence - the minimum confidence threshold
      Returns:
      a new extractor with the specified threshold