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

Adding functionality for multi-column ingestion into vector databases and skills #8990

Open
wants to merge 4 commits into
base: staging
Choose a base branch
from

Conversation

QuantumPlumber
Copy link
Contributor

Description

Current vector database and knowledge base implementation does not allow for multi-column insertion, even though the langchain_embeddings handler does support multi-column embedding. The langchain_embeddings handler concatentates the row entries as context for the embedding, but does not return this concatenation. Therefore, the actual context provided to the embedding model remains hidden. This PR explicitly returns the embedding context as the embedding_context column.

The knowledge base insert statement is modified to handle the protected embedding_context column.

embedding_context is registered as a protected column name for the vector database integration.

Fixes #issue_number

Type of change

(Please delete options that are not relevant)

  • 🐛 Bug fix (non-breaking change which fixes an issue)
  • [x ] ⚡ New feature (non-breaking change which adds functionality)
  • 📢 Breaking change (fix or feature that would cause existing functionality not to work as expected)
  • [ x] 📄 This change requires a documentation update

Verification Process

To ensure the changes are working as expected:

Tested locally on most up-to-date staging branch.

  • Test Location: Specify the URL or path for testing.
  • Verification Steps: Outline the steps or queries needed to validate the change. Include any data, configurations, or actions required to reproduce or see the new functionality.

Additional Media:

  • I have attached a brief loom video or screenshots showcasing the new functionality or change.

Checklist:

  • [ x] My code follows the style guidelines(PEP 8) of MindsDB.
  • [ x] I have appropriately commented on my code, especially in complex areas.
  • Necessary documentation updates are either made or tracked in issues.
  • Relevant unit and integration tests are updated or added.

Copy link
Contributor

@tmichaeldb tmichaeldb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for tackling this! Just need to update the rest of the embedding handlers, and (preferably) add some tests.


# rename model's 'embedding_context' column to 'content'
df = df.rename(
columns={TableField.CONTEXT.value: TableField.CONTENT.value}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This currently only works with langchain_embedding_handler, because it is the only handler that adds this embedding_context column.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

gotcha, adding it to the sentence transformer.

Copy link
Contributor

Choose a reason for hiding this comment

The 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

@@ -161,7 +161,7 @@ def predict(self, df: DataFrame, args) -> DataFrame:
embeddings = model.embed_documents(df_texts.tolist())

# create a new dataframe with the embeddings
df_embeddings = df.copy().assign(**{target: embeddings})
df_embeddings = df.copy().assign(**{'embedding_context': df_texts, target: embeddings})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

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.

@@ -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.drop(TableField.CONTENT.value, axis='columns')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The original content may be different from the embedding_context and is good to have still. Is there any major downside to keeping both columns?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The original content we can name something else.. I dropped it because we have to rename the embedding_context as the content to preserve the rest of the functionality.

@ea-rus ea-rus mentioned this pull request Mar 28, 2024
11 tasks
@ea-rus
Copy link
Contributor

ea-rus commented Apr 24, 2024

This PR should be covered by #9005

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

Successfully merging this pull request may close these issues.

None yet

4 participants