Skip to content

Commit 813efa9

Browse files
committed
allow disabling reranker
1 parent 31ba4dd commit 813efa9

File tree

4 files changed

+21
-6
lines changed

4 files changed

+21
-6
lines changed

src/Client/KnowledgeBaseClient.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,14 @@ public function destroy(mixed $id): bool
5858
* @param array<string> $entities The entities to search for.
5959
* @param array<string:string> $where The entities to search for.
6060
*/
61-
public function query(string $text, int $k = 10, ?array $entities = null, ?array $where = null, float $minScore = 0.05): KnowledgeBaseQueryResponse
61+
public function query(
62+
string $text,
63+
int $k = 10,
64+
?array $entities = null,
65+
?array $where = null,
66+
float $minScore = 0.05,
67+
bool $useReranker = false,
68+
): KnowledgeBaseQueryResponse
6269
{
6370
logger()->debug('[KnowledgeBaseClient] Querying knowledge base', [
6471
'text' => $text,
@@ -71,6 +78,7 @@ public function query(string $text, int $k = 10, ?array $entities = null, ?array
7178
'query' => $text,
7279
'k' => $k,
7380
'min_score' => $minScore,
81+
'use_rerank' => $useReranker,
7482
];
7583

7684
if ($entities) {

src/DTO/KnowledgeBaseQueryResponseItem.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public static function from(array $result): static
2020
id: $result['id'],
2121
entity: $result['entity'],
2222
text: $result['text'],
23-
rerankingScore: $result['score'],
23+
rerankingScore: $result['score'] ?? 0,
2424
payload: $result['payload'] ?? null,
2525
);
2626
}

src/KnowledgeBase.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,18 @@ public function destroy(Model $model): bool
3939
return true;
4040
}
4141

42-
public function query(string $text, int $k = 10, ?array $entities = null, ?array $where = null, float $minScore = 0.05): KnowledgeBaseQueryResponse
42+
public function query(
43+
string $text,
44+
int $k = 10,
45+
?array $entities = null,
46+
?array $where = null,
47+
float $minScore = 0.05,
48+
bool $useReranker = false,
49+
): KnowledgeBaseQueryResponse
4350
{
4451
$client = new KnowledgeBaseClient();
4552

46-
return $client->query($text, $k, $entities, $where, $minScore);
53+
return $client->query($text, $k, $entities, $where, $minScore, $useReranker);
4754
}
4855

4956
/**

src/Traits/BelongsToKnowledgeBase.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,8 @@ public function knowledgeInsertItems(): array
9191
return $items;
9292
}
9393

94-
public static function searchInKnowledgeBase(string $query, int $k = 10, ?array $where = null, float $minScore = 0.05): KnowledgeBaseQueryResponse
94+
public static function searchInKnowledgeBase(string $query, int $k = 10, ?array $where = null, float $minScore = 0.05, bool $useReranker = false): KnowledgeBaseQueryResponse
9595
{
96-
return KnowledgeBase::query($query, $k, [class_basename(static::class)], $where, $minScore);
96+
return KnowledgeBase::query($query, $k, [class_basename(static::class)], $where, $minScore, $useReranker);
9797
}
9898
}

0 commit comments

Comments
 (0)