mirror of
https://github.com/mruwnik/memory.git
synced 2025-06-28 23:24:43 +02:00
order sources from search
This commit is contained in:
parent
96c2f22b16
commit
510cfdf82f
@ -101,4 +101,7 @@ async def search(
|
||||
)
|
||||
if settings.ENABLE_SEARCH_SCORING:
|
||||
chunks = await scorer.rank_chunks(data[0].data[0], chunks, min_score=0.3)
|
||||
return await search_sources(chunks, previews)
|
||||
|
||||
sources = await search_sources(chunks, previews)
|
||||
sources.sort(key=lambda x: x.search_score or 0, reverse=True)
|
||||
return sources
|
||||
|
@ -32,6 +32,7 @@ class SearchResult(BaseModel):
|
||||
tags: list[str] | None = None
|
||||
metadata: dict | None = None
|
||||
created_at: datetime | None = None
|
||||
search_score: float | None = None
|
||||
|
||||
@classmethod
|
||||
def from_source_item(
|
||||
@ -41,6 +42,8 @@ class SearchResult(BaseModel):
|
||||
metadata.pop("content", None)
|
||||
chunk_size = settings.DEFAULT_CHUNK_TOKENS * 4
|
||||
|
||||
search_score = sum(chunk.relevance_score for chunk in chunks)
|
||||
|
||||
return cls(
|
||||
id=cast(int, source.id),
|
||||
size=cast(int, source.size),
|
||||
@ -56,6 +59,7 @@ class SearchResult(BaseModel):
|
||||
tags=cast(list[str], source.tags),
|
||||
metadata=metadata,
|
||||
created_at=cast(datetime | None, source.inserted_at),
|
||||
search_score=search_score,
|
||||
)
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user