Interface KnowledgeStore<C>

Type Parameters:
C - category type used to partition documents (e.g. an enum or String)
All Known Implementing Classes:
InMemoryKnowledgeStore

public interface KnowledgeStore<C>
Storage and retrieval interface for KnowledgeDocument instances.

Implementations may use keyword matching (InMemoryKnowledgeStore), dense-vector similarity, or hybrid strategies. The contract is intentionally minimal so all backends can be substituted transparently.

Example usage:


 KnowledgeStore<SupportIntent> store = new InMemoryKnowledgeStore<>();
 store.add(new KnowledgeDocument<>("faq-001", "Return policy", "...",
     SupportIntent.RETURNS, Set.of("return", "refund")));

 List<KnowledgeDocument<SupportIntent>> results = store.search("refund", 3);
 
  • Method Details

    • add

      void add(KnowledgeDocument<C> document)
      Adds or replaces a document.

      If a document with the same id already exists it is silently replaced (last-write-wins semantics).

      Parameters:
      document - document to store (non-null)
    • getById

      Returns the document with the given ID, or Optional.empty() if no such document exists.
      Parameters:
      id - document identifier (non-null)
      Returns:
      matching document or empty
    • search

      List<KnowledgeDocument<C>> search(String query, int topK)
      Returns up to topK documents ordered by descending relevance to query across all categories.
      Parameters:
      query - search query (non-null)
      topK - maximum number of results to return (> 0)
      Returns:
      ordered list of matching documents; never null
    • searchByCategory

      List<KnowledgeDocument<C>> searchByCategory(String query, C category, int topK)
      Returns up to topK documents restricted to category, ordered by descending relevance to query.
      Parameters:
      query - search query (non-null)
      category - category filter (non-null)
      topK - maximum number of results to return (> 0)
      Returns:
      ordered list of matching documents; never null
    • getByCategory

      List<KnowledgeDocument<C>> getByCategory(C category)
      Returns all documents belonging to category in unspecified order.
      Parameters:
      category - category filter (non-null)
      Returns:
      list of documents; never null, may be empty
    • size

      int size()
      Returns the total number of documents currently stored.
      Returns:
      document count (>= 0)