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
Adding functionality for multi-column ingestion into vector databases and skills #8990
base: main
Are you sure you want to change the base?
Changes from all commits
c36ff6b
bd416df
6012122
64f259e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,8 @@ | |
from mindsdb.integrations.libs.vectordatabase_handler import TableField | ||
from mindsdb.utilities.exception import EntityExistsError, EntityNotExistsError | ||
|
||
from mindsdb.utilities import log | ||
logger = log.getLogger(__name__) | ||
|
||
class KnowledgeBaseTable: | ||
""" | ||
|
@@ -126,6 +128,15 @@ def insert(self, df: pd.DataFrame): | |
df_emb = self._df_to_embeddings(df) | ||
df = pd.concat([df, df_emb], axis=1) | ||
|
||
# drop original 'content' column if it exists | ||
if TableField.CONTENT.value in df.columns: | ||
df = df.rename(columns={TableField.CONTENT.value: "original_context"}) | ||
|
||
# rename model's 'embedding_context' column to 'content' | ||
df = df.rename( | ||
columns={TableField.CONTEXT.value: TableField.CONTENT.value} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This currently only works with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. gotcha, adding it to the sentence transformer. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @QuantumPlumber perhaps worth us creating a base Embedding class like we have for vector stores |
||
) | ||
|
||
# send to vector db | ||
db_handler = self._get_vector_db() | ||
db_handler.do_upsert(self._kb.vector_database_table, df) | ||
|
@@ -185,7 +196,7 @@ def _df_to_embeddings(self, df: pd.DataFrame) -> pd.DataFrame: | |
if target != TableField.EMBEDDINGS.value: | ||
# adapt output for vectordb | ||
df_out = df_out.rename(columns={target: TableField.EMBEDDINGS.value}) | ||
df_out = df_out[[TableField.EMBEDDINGS.value]] | ||
df_out = df_out[[TableField.CONTEXT.value, TableField.EMBEDDINGS.value]] | ||
|
||
return df_out | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We would need to update this for all embedding handlers (e.g. https://github.com/mindsdb/mindsdb/blob/staging/mindsdb/integrations/handlers/sentence_transformers_handler/sentence_transformers_handler.py#L66)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The sentence transformer is more transparent, the input to the model is just the document, so we can duplicate that entry in the dataframe.