Base KnowledgeStore¶
Base Knowledge Store.
BaseKnowledgeStore
¶
Bases: BaseModel
, ABC
Base Knowledge Store Class.
This class represent the base knowledge store component of a RAG system.
Attributes:
Name | Type | Description |
---|---|---|
name |
str
|
The name of knowledge store. |
Source code in src/fed_rag/base/knowledge_store.py
load_node
abstractmethod
¶
Load a "KnowledgeNode" into the KnowledgeStore.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
node
|
KnowledgeNode
|
The node to load to the knowledge store. |
required |
load_nodes
abstractmethod
¶
Load multiple "KnowledgeNode"s in batch.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
nodes
|
list[KnowledgeNode]
|
The nodes to load. |
required |
retrieve
abstractmethod
¶
Retrieve top-k nodes from KnowledgeStore against a provided user query.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
query_emb
|
list[float]
|
the query represented as an encoded vector. |
required |
top_k
|
int
|
the number of knowledge nodes to retrieve. |
required |
Returns:
Type | Description |
---|---|
list[tuple[float, KnowledgeNode]]
|
A list of tuples where the first element represents the similarity score |
list[tuple[float, KnowledgeNode]]
|
of the node to the query, and the second element is the node itself. |
Source code in src/fed_rag/base/knowledge_store.py
batch_retrieve
abstractmethod
¶
Batch retrieve top-k nodes from KnowledgeStore against provided user queries.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
query_embs
|
list[list[float]]
|
the list of encoded queries. |
required |
top_k
|
int
|
the number of knowledge nodes to retrieve. |
required |
Returns:
Type | Description |
---|---|
list[list[tuple[float, KnowledgeNode]]]
|
A list of list of tuples where the first element represents the similarity score |
list[list[tuple[float, KnowledgeNode]]]
|
of the node to the query, and the second element is the node itself. |
Source code in src/fed_rag/base/knowledge_store.py
delete_node
abstractmethod
¶
Remove a node from the KnowledgeStore by ID, returning success status.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
node_id
|
str
|
The id of the node to delete. |
required |
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
Whether or not the node was successfully deleted. |