mirror of
https://github.com/langbot-app/LangBot.git
synced 2026-06-02 20:14:36 +00:00
* Initial plan * Add backend support for external knowledge bases Co-authored-by: RockChinQ <45992437+RockChinQ@users.noreply.github.com> * Add frontend support for external knowledge bases with tabs UI Co-authored-by: RockChinQ <45992437+RockChinQ@users.noreply.github.com> * Add i18n translations for all languages (Traditional Chinese and Japanese) Co-authored-by: RockChinQ <45992437+RockChinQ@users.noreply.github.com> * Update knowledge base tab list styling to match plugins page Co-authored-by: RockChinQ <45992437+RockChinQ@users.noreply.github.com> * perf: margin-top for kb page * refactor: switch RetrievalResultEntry to langbot_plugin pkg ones * feat: knowledge retriever listing and creating * stash * refactor: unify sync mechanism for polymorphic components * feat: use unified retireval result struct in retrieval test page * chore: remove unused methods * feat: retriever icon displaying * feat: localagent retrieval with external kbs * chore: bump version of langbot-plugin to 0.2.0b1 * fix: i18n --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: RockChinQ <45992437+RockChinQ@users.noreply.github.com> Co-authored-by: Junyan Qin <rockchinq@gmail.com>
56 lines
1.3 KiB
Python
56 lines
1.3 KiB
Python
"""Base classes and interfaces for knowledge bases"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import abc
|
|
|
|
from langbot.pkg.core import app
|
|
from langbot_plugin.api.entities.builtin.rag import context as rag_context
|
|
|
|
|
|
class KnowledgeBaseInterface(metaclass=abc.ABCMeta):
|
|
"""Abstract interface for all knowledge base types"""
|
|
|
|
ap: app.Application
|
|
|
|
def __init__(self, ap: app.Application):
|
|
self.ap = ap
|
|
|
|
@abc.abstractmethod
|
|
async def initialize(self):
|
|
"""Initialize the knowledge base"""
|
|
pass
|
|
|
|
@abc.abstractmethod
|
|
async def retrieve(self, query: str, top_k: int) -> list[rag_context.RetrievalResultEntry]:
|
|
"""Retrieve relevant documents from the knowledge base
|
|
|
|
Args:
|
|
query: The query string
|
|
top_k: Number of top results to return
|
|
|
|
Returns:
|
|
List of retrieve result entries
|
|
"""
|
|
pass
|
|
|
|
@abc.abstractmethod
|
|
def get_uuid(self) -> str:
|
|
"""Get the UUID of the knowledge base"""
|
|
pass
|
|
|
|
@abc.abstractmethod
|
|
def get_name(self) -> str:
|
|
"""Get the name of the knowledge base"""
|
|
pass
|
|
|
|
@abc.abstractmethod
|
|
def get_type(self) -> str:
|
|
"""Get the type of knowledge base (internal/external)"""
|
|
pass
|
|
|
|
@abc.abstractmethod
|
|
async def dispose(self):
|
|
"""Clean up resources"""
|
|
pass
|