Skip to content

Commit 6b2395e

Browse files
committed
allow setting min score
1 parent 70e8262 commit 6b2395e

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

src/Client/KnowledgeBaseClient.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,17 +58,19 @@ 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): KnowledgeBaseQueryResponse
61+
public function query(string $text, int $k = 10, ?array $entities = null, ?array $where = null, float $minScore = 0.05): KnowledgeBaseQueryResponse
6262
{
6363
logger()->debug('[KnowledgeBaseClient] Querying knowledge base', [
6464
'text' => $text,
6565
'k' => $k,
6666
'entities' => $entities,
6767
'where' => $where,
68+
'minScore' => $minScore,
6869
]);
6970
$params = [
7071
'query' => $text,
7172
'k' => $k,
73+
'min_score' => $minScore,
7274
];
7375

7476
if ($entities) {

src/Traits/BelongsToKnowledgeBase.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public function knowledgeBasePayload(): array
3838
return [];
3939
}
4040

41-
public function knowledgeBaseKeyAttribute(): ?string
41+
public function knowledgeBaseKeyAttribute(): ?string
4242
{
4343
return null;
4444
}
@@ -66,7 +66,7 @@ public function knowledgeInsertItems(): array
6666
}
6767

6868
$key = $this->knowledgeBaseKeyAttribute() ? $this->{$this->knowledgeBaseKeyAttribute()} : $this->getKey();
69-
69+
7070
$items[] = new KnowledgeInsertItem(
7171
id: $chunk->id,
7272
entity: $text->entity,
@@ -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): KnowledgeBaseQueryResponse
94+
public static function searchInKnowledgeBase(string $query, int $k = 10, ?array $where = null, float $minScore = 0.05): KnowledgeBaseQueryResponse
9595
{
96-
return KnowledgeBase::query($query, $k, [class_basename(static::class)], $where);
96+
return KnowledgeBase::query($query, $k, [class_basename(static::class)], $where, $minScore);
9797
}
9898
}

0 commit comments

Comments
 (0)