hybrid search #20

Closed
opened 2026-02-16 05:16:07 -05:00 by yindo · 3 comments
Owner

Originally created by @gecBurton on GitHub (May 31, 2024).

Not an "issue" I know, but would it be possible to have a hybrid full-text/vector search similar to https://www.alibabacloud.com/help/en/analyticdb-for-postgresql/user-guide/fusion-search-use-guide?

Originally created by @gecBurton on GitHub (May 31, 2024). Not an "issue" I know, but would it be possible to have a hybrid full-text/vector search similar to https://www.alibabacloud.com/help/en/analyticdb-for-postgresql/user-guide/fusion-search-use-guide?
yindo closed this issue 2026-02-16 05:16:07 -05:00
Author
Owner

@gecBurton commented on GitHub (Jun 19, 2024):

any thoughts on this?

I am thinking something like:

query = "who were the leading figures in the french revolution?"

h = 1

index_vector = func.to_tsvector("english", vectorstore.EmbeddingStore.document)
search_vector = func.plainto_tsquery("english", " | ".join(query.split(" ")))
fulltext_search = func.ts_rank(index_vector, search_vector)

embedding = embedder.embed_query(query)
vector_search = vectorstore.distance_strategy(embedding)

results = session.query(
    vectorstore.EmbeddingStore,
    (vector_search * (1-h) + fulltext_search * h).label("distance")
).order_by(desc("distance"))


for doc, score in vectorstore._results_to_docs_and_scores(results):
    print(doc.page_content)

if this is of interest Ill raise a PR.

@gecBurton commented on GitHub (Jun 19, 2024): any thoughts on this? I am thinking something like: ```python query = "who were the leading figures in the french revolution?" h = 1 index_vector = func.to_tsvector("english", vectorstore.EmbeddingStore.document) search_vector = func.plainto_tsquery("english", " | ".join(query.split(" "))) fulltext_search = func.ts_rank(index_vector, search_vector) embedding = embedder.embed_query(query) vector_search = vectorstore.distance_strategy(embedding) results = session.query( vectorstore.EmbeddingStore, (vector_search * (1-h) + fulltext_search * h).label("distance") ).order_by(desc("distance")) for doc, score in vectorstore._results_to_docs_and_scores(results): print(doc.page_content) ``` if this is of interest Ill raise a PR.
Author
Owner

@salmatfq commented on GitHub (Jan 29, 2025):

Any updates on this? I’d love to see hybrid search support in PGVector! It would help tremendously.
I'd be happy to contribute if needed.

@salmatfq commented on GitHub (Jan 29, 2025): Any updates on this? I’d love to see hybrid search support in PGVector! It would help tremendously. I'd be happy to contribute if needed.
Author
Owner

@gecBurton commented on GitHub (Apr 27, 2025):

im closing this issue in favour of https://github.com/langchain-ai/langchain-postgres/issues/71

@gecBurton commented on GitHub (Apr 27, 2025): im closing this issue in favour of https://github.com/langchain-ai/langchain-postgres/issues/71
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langchain-ai/langchain-postgres#20