Skip to content
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

Making use of sqlite-vec's metadata filtering #11

Open
forrestbao opened this issue Nov 21, 2024 · 1 comment
Open

Making use of sqlite-vec's metadata filtering #11

forrestbao opened this issue Nov 21, 2024 · 1 comment
Assignees

Comments

@forrestbao
Copy link
Member

forrestbao commented Nov 21, 2024

We previously manually do metadata filtering. Now sqlite-vec just added this ability. So we can simplify our code with that asg017/sqlite-vec#26

@forrestbao forrestbao changed the title Making use of sqlite-vec's metadata filterinbg Making use of sqlite-vec's metadata filtering Jan 2, 2025
@forrestbao
Copy link
Member Author

Two changes need to be made here:

First, combine the tables chunks with embeddings by adding a column embedding in chunks to store the vector embedding of texts in the column text.

Then perform metadata (here the metadata is sample_id and text_type) filtering in SQL like this:

opposite_text_type = {'source': 'summary', 'summary': 'source'}

sql_cmd = 
f"
SELECT
        chunk_id,
        distance
    FROM embeddings
    WHERE embedding MATCH {embedding_of_selected_text_span: str}
    AND sample_id = {sample_id_of_selected_text_span: int}
    AND text_type = opposite_text_type[text_type_of_selected_text_span: str]
    ORDER BY distance
"

For more details, see this blog post of sqlite-vec. To understand embeddings and vector search in general, try this Youtube video.

Below is our current manual row filtering

https://github.com/TexteaInc/mercury/blob/sqlite/README.md?plain=1#L232-L292

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