Package dev.agenor.core.knowledge
Interface KnowledgeStore<C>
- Type Parameters:
C- category type used to partition documents (e.g. an enum orString)
- 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 Summary
Modifier and TypeMethodDescriptionvoidadd(KnowledgeDocument<C> document) Adds or replaces a document.getByCategory(C category) Returns all documents belonging tocategoryin unspecified order.Returns the document with the given ID, orOptional.empty()if no such document exists.Returns up totopKdocuments ordered by descending relevance toqueryacross all categories.searchByCategory(String query, C category, int topK) Returns up totopKdocuments restricted tocategory, ordered by descending relevance toquery.intsize()Returns the total number of documents currently stored.
-
Method Details
-
add
Adds or replaces a document.If a document with the same
idalready exists it is silently replaced (last-write-wins semantics).- Parameters:
document- document to store (non-null)
-
getById
Returns the document with the given ID, orOptional.empty()if no such document exists.- Parameters:
id- document identifier (non-null)- Returns:
- matching document or empty
-
search
Returns up totopKdocuments ordered by descending relevance toqueryacross 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
Returns up totopKdocuments restricted tocategory, ordered by descending relevance toquery.- 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
Returns all documents belonging tocategoryin 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)
-