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

fix: support minimal llama-index installations #2516

Merged
merged 4 commits into from
Mar 9, 2024

Conversation

axiomofjoy
Copy link
Contributor

Adds support for minimal LlamaIndex installations, i.e., when only the llama-index-core module is installed but not the full llama-index package.

resolves #2509

@dosubot dosubot bot added the size:M This PR changes 30-99 lines, ignoring generated files. label Mar 9, 2024
Copy link
Contributor

@mikeldking mikeldking left a comment

Choose a reason for hiding this comment

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

I'm not sure I understand the conditionals. Can you make it a bit clearer? I think if llama-index is installed in modern you get core by default. That might be the simplest approach.

src/phoenix/trace/llama_index/callback.py Outdated Show resolved Hide resolved
Comment on lines 33 to 39
if llama_index_version_str is None:
if llama_index_core_version_str is None:
raise PackageNotFoundError(
"Missing `llama_index`. "
"Install with `pip install llama-index` or "
"`pip install llama-index-core` for a minimal installation."
)
Copy link
Contributor

Choose a reason for hiding this comment

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

why not just combine these conditionals with an or?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I could combine with an and, but then I would need to do an additional conditional to handle the case where llama-index-core is installed but the instrumentation is out of date.

There are four cases I was checking for:

  • The user has neither llama-index nor llama-index-core installed.
  • The user has only llama-index-core installed, but an old version of the instrumentation.
  • The user has an old version of llama-index installed and a modern version of the instrumentation.
  • The user has a modern version of llama-index installed and an old version of the instrumentation.

Comment on lines 40 to 46
if instrumentation_version < INSTRUMENTATION_MODERN_VERSION:
raise IncompatibleLibraryVersionError(
f"llama-index-core v{llama_index_core_version_str} is not compatible with "
f"openinference-instrumentation-llama-index v{instrumentation_version_str}. "
"Please upgrade openinference-instrumentation-llama-index to at least 1.0.0 via "
"`pip install 'openinference-instrumentation-llama-index>=1.0.0'`."
)
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe I'm reading the indentation wrong but I feel this is in the wrong place?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This condition is checking for the case where llama-index-core is installed but llama-index is not installed. In that case, I am checking whether the current version of the instrumentation is compatible.

Copy link
Contributor

Choose a reason for hiding this comment

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

I see, yeah the conditionals a a bit confusing. I think it may be good to explain your logic here a bit as it's quite confusing to map the conditionals

"Please upgrade openinference-instrumentation-llama-index to at least 1.0.0 via "
"`pip install 'openinference-instrumentation-llama-index>=1.0.0'`."
)
return True
Copy link
Contributor

Choose a reason for hiding this comment

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

Explain this true - e.g. -core existence means that the instrumentation is modern "enough"

Copy link
Contributor Author

@axiomofjoy axiomofjoy Mar 9, 2024

Choose a reason for hiding this comment

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

This return statement corresponds to the case where only llama-index-core is installed and a modern version of our instrumentation is installed.

Comment on lines 20 to 30
llama_index_version_str = None
try:
llama_index_version_str = version("llama-index")
except PackageNotFoundError:
pass

llama_index_core_version_str = None
try:
llama_index_core_version_str = version("llama-index-core")
except PackageNotFoundError:
pass
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
llama_index_version_str = None
try:
llama_index_version_str = version("llama-index")
except PackageNotFoundError:
pass
llama_index_core_version_str = None
try:
llama_index_core_version_str = version("llama-index-core")
except PackageNotFoundError:
pass
llama_index_version_str = None
llama_index_core_version_str = None
try:
llama_index_version_str = version("llama-index")
except PackageNotFoundError:
pass
try:
llama_index_core_version_str = version("llama-index-core")
except PackageNotFoundError:
pass

alternatively you could just make a function get_packege_version(package_name: str): Optional[str] that does this. I think that would read cleaner.

@axiomofjoy
Copy link
Contributor Author

Simplified, hopefully that is more readable @mikeldking

@axiomofjoy axiomofjoy merged commit 2469677 into main Mar 9, 2024
11 checks passed
@axiomofjoy axiomofjoy deleted the check-version-of-llama-index-core-2509 branch March 9, 2024 06:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
size:M This PR changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG] Import error using llama-index-core
2 participants