Skip to content

Commit 7bd70cf

Browse files
AlexShen-Oguricodex
andcommitted
Run single-connection hybrid queries in sequence
The semantic and keyword queries share a Psycopg connection, which serializes cursor operations. Preserve the result order for reranking. Co-authored-by: OpenAI Codex <codex@openai.com>
1 parent d2ace87 commit 7bd70cf

1 file changed

Lines changed: 4 additions & 3 deletions

File tree

‎examples/hybrid_search/cross_encoder.py‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,10 @@ async def main():
6464
await create_schema(conn)
6565
await insert_data(conn)
6666

67-
# perform queries in parallel
68-
results = await asyncio.gather(semantic_search(conn, query), keyword_search(conn, query))
69-
results = rerank(query, results)
67+
# Psycopg serializes queries on a shared connection.
68+
semantic_results = await semantic_search(conn, query)
69+
keyword_results = await keyword_search(conn, query)
70+
results = rerank(query, [semantic_results, keyword_results])
7071
print(results)
7172

7273

0 commit comments

Comments
 (0)