mirror of
https://github.com/crewAIInc/crewAI.git
synced 2026-01-22 14:48:13 +00:00
Adding core knowledge sources
This commit is contained in:
32
path/to/src/crewai/knowledge/source/base_knowledge_source.py
Normal file
32
path/to/src/crewai/knowledge/source/base_knowledge_source.py
Normal file
@@ -0,0 +1,32 @@
|
||||
from abc import ABC, abstractmethod
|
||||
from typing import List
|
||||
|
||||
from crewai.knowledge.embedder.base_embedder import BaseEmbedder
|
||||
|
||||
|
||||
class BaseKnowledgeSource(ABC):
|
||||
"""Abstract base class for different types of knowledge sources."""
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
chunk_size: int = 1000,
|
||||
chunk_overlap: int = 200,
|
||||
):
|
||||
self.chunk_size = chunk_size
|
||||
self.chunk_overlap = chunk_overlap
|
||||
self.chunks: List[str] = []
|
||||
|
||||
@abstractmethod
|
||||
def load_content(self):
|
||||
"""Load and preprocess content from the source."""
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def add(self, embedder: BaseEmbedder) -> None:
|
||||
"""Add content to the knowledge base, chunk it, and compute embeddings."""
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def query(self, embedder: BaseEmbedder, query: str, top_k: int = 3) -> str:
|
||||
"""Query the knowledge base using semantic search."""
|
||||
pass
|
||||
Reference in New Issue
Block a user