Skip to content

hybrid search #61

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
gecBurton opened this issue May 31, 2024 · 3 comments
Closed

hybrid search #61

gecBurton opened this issue May 31, 2024 · 3 comments

Comments

@gecBurton
Copy link

gecBurton commented 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?

@gecBurton
Copy link
Author

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.

@salmatfq
Copy link

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.

@gecBurton
Copy link
Author

im closing this issue in favour of #71

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants