From 96c2f22b16f9ef2e45776613aae5020d58474cdf Mon Sep 17 00:00:00 2001 From: EC2 Default User Date: Sat, 28 Jun 2025 19:22:03 +0000 Subject: [PATCH] tweaks for search scoring --- docker-compose.yaml | 4 +++- src/memory/api/search/scorer.py | 25 +++++++++++++++++-------- src/memory/api/search/search.py | 2 +- 3 files changed, 21 insertions(+), 10 deletions(-) diff --git a/docker-compose.yaml b/docker-compose.yaml index bd3e5d6..a395aec 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -156,7 +156,9 @@ services: STATIC_DIR: "/app/static" VOYAGE_API_KEY: ${VOYAGE_API_KEY} ENABLE_BM25_SEARCH: false - secrets: [postgres_password] + OPENAI_API_KEY_FILE: /run/secrets/openai_key + ANTHROPIC_API_KEY_FILE: /run/secrets/anthropic_key + secrets: [postgres_password, openai_key, anthropic_key] volumes: - ./memory_files:/app/memory_files:rw healthcheck: diff --git a/src/memory/api/search/scorer.py b/src/memory/api/search/scorer.py index bf40315..d978f98 100644 --- a/src/memory/api/search/scorer.py +++ b/src/memory/api/search/scorer.py @@ -29,17 +29,26 @@ Please always return a summary of any images provided. async def score_chunk(query: str, chunk: Chunk) -> Chunk: - data = chunk.data + try: + data = chunk.data + except Exception as e: + print(f"Error getting chunk data: {e}, {type(e)}") + return chunk + chunk_text = "\n".join(text for text in data if isinstance(text, str)) images = [image for image in data if isinstance(image, Image.Image)] prompt = SCORE_CHUNK_PROMPT.format(query=query, chunk=chunk_text) - response = await asyncio.to_thread( - llms.call, - prompt, - settings.RANKER_MODEL, - images=images, - system_prompt=SCORE_CHUNK_SYSTEM_PROMPT, - ) + try: + response = await asyncio.to_thread( + llms.call, + prompt, + settings.RANKER_MODEL, + images=images, + system_prompt=SCORE_CHUNK_SYSTEM_PROMPT, + ) + except Exception as e: + print(f"Error scoring chunk: {e}, {type(e)}") + return chunk soup = BeautifulSoup(response, "html.parser") if not (score := soup.find("score")): diff --git a/src/memory/api/search/search.py b/src/memory/api/search/search.py index 0df208c..0c07484 100644 --- a/src/memory/api/search/search.py +++ b/src/memory/api/search/search.py @@ -77,7 +77,7 @@ async def search( modalities: set[str] = set(), limit: int = 10, filters: SearchFilters = {}, - timeout: int = 2, + timeout: int = 20, ) -> list[SearchResult]: """ Search across knowledge base using text query and optional files.