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

Add New Integration for DeepInfra Embedding Model #1

Merged
merged 15 commits into from
May 7, 2024

Conversation

ovuruska
Copy link
Owner

@ovuruska ovuruska commented May 2, 2024

Description
This pull request introduces a new integration for the DeepInfra Inference API.

Motivation and Context
Users are able to use DeepInfra's models using llama_index.

Fixes

  • No specific issue fixed; this is a new feature addition.

New Package?

  • Yes
  • No

If yes, I have filled in the tool.llamahub section in the pyproject.toml and provided a detailed README.md for my new integration.

Version Bump?

  • Yes
  • No

Type of Change

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

How Has This Been Tested?

  • Tests have been added to verify the functionality of the new embedding model integration. These tests ensure that both synchronous and asynchronous methods perform as expected.
  • Added new unit/integration tests
  • Added new notebook (that tests end-to-end)
  • I stared at the code and made sure it makes sense

Suggested Checklist:

  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I have added Google Colab support for the newly added notebooks.
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • I ran make format; make lint to appease the lint gods

@ovuruska ovuruska marked this pull request as draft May 2, 2024 15:07
@ovuruska ovuruska self-assigned this May 3, 2024
@ovuruska ovuruska changed the title bootstrapped Add New Integration for DeepInfra Embedding Model May 3, 2024
@ovuruska ovuruska marked this pull request as ready for review May 3, 2024 16:19
@ichernev
Copy link

ichernev commented May 3, 2024

I don't see the code that does the auto-batching (the one you added for lang-chain). Other than that it looks like a standalone project, which is probably how this is organized.

Other than that looks good.


async def _aget_query_embedding(self, query: str) -> List[float]:
"""
Async get query embedding.
Copy link

Choose a reason for hiding this comment

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

Async here? We do some sharing of sync and async code by computing headers, url and body in methods and calling those in sync and async requests/HTTP client APIs

@ichernev
Copy link

ichernev commented May 3, 2024

Also implement sync and async.

Also what is the difference between text and query? Actually some models do make a difference (normally you prefix the text with query: or prompt: or sth similar)

@@ -0,0 +1,3 @@
poetry_requirements(
name="poetry",
Copy link

Choose a reason for hiding this comment

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

Are you sure you need this? I mean if you already have poetry_requirements that would require poetry to read, no?

from dotenv import load_dotenv, find_dotenv
from llama_index.embeddings.deepinfra import DeepInfraEmbeddingModel

_ = load_dotenv(find_dotenv())
Copy link

Choose a reason for hiding this comment

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

Maybe a comment to explain what are you loading exactly, not obvious to me.

print(response)
```

### Use with text prefix
Copy link

Choose a reason for hiding this comment

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

There should be one example which passes both query and text prefixes, with a short description on why that would be useful. I don't see how having two examples is better.

"""
Add query prefix to queries.
"""
return [self._query_prefix + query for query in queries]
Copy link

Choose a reason for hiding this comment

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

You can do [self._query_prefix + query for query in queries] if self._query_prefix else queries so it doesn't slow things down without query prefix

print(response)
```

### Asynchronous requests
Copy link

Choose a reason for hiding this comment

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

I guess if all others have these verbose examples then fine, but the setup is the same, only the method call is different, and even that is the API of the BaseEmbedding (i.e nothing deepinfra specific). So you decide if you keep this or shorten it a bit (maybe a single setup + multiple fn calls).

Copy link
Owner Author

@ovuruska ovuruska May 7, 2024

Choose a reason for hiding this comment

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

Dealt with it. Decreased the code repetition.

"""
Chunk items into batches of size MAX_BATCH_SIZE.
"""
return [items[i : i + MAX_BATCH_SIZE] for i in range(0, len(items), MAX_BATCH_SIZE)]
Copy link

Choose a reason for hiding this comment

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

MAX_BATCH_SIZE can be a constructor arg, and this function can be a method

Copy link
Owner Author

Choose a reason for hiding this comment

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

Isn't this parameter related with deepinfra's backend?

@ichernev
Copy link

ichernev commented May 7, 2024

Looks good, send it upstream!

@ovuruska ovuruska merged commit 5c11e6f into main May 7, 2024
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.

2 participants