Skip to content

Commit 4ce74d0

Browse files
committed
retrieval tool
1 parent 2118ede commit 4ce74d0

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace NeuronAI\Tools\Toolkits;
6+
7+
use NeuronAI\Chat\Messages\UserMessage;
8+
use NeuronAI\RAG\Retrieval\RetrievalInterface;
9+
use NeuronAI\Tools\PropertyType;
10+
use NeuronAI\Tools\Tool;
11+
use NeuronAI\Tools\ToolProperty;
12+
13+
class RetrievalTool extends Tool
14+
{
15+
public function __construct(
16+
protected RetrievalInterface $retrieval
17+
) {
18+
parent::__construct(
19+
name: 'context_retrieval',
20+
description: 'Search for documents similar to a given query.',
21+
);
22+
}
23+
24+
protected function properties(): array
25+
{
26+
return [
27+
new ToolProperty(
28+
name: 'query',
29+
type: PropertyType::STRING,
30+
description: 'The query to retrieve documents for.',
31+
required: true
32+
)
33+
];
34+
}
35+
36+
public function __invoke(string $query): array
37+
{
38+
return $this->retrieval->retrieve(new UserMessage($query));
39+
}
40+
}

0 commit comments

Comments
 (0)