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

[Feature Request]: Support metadata on queryEngine, invocations - make them available to the callback system #10532

Closed
mikeldking opened this issue Feb 8, 2024 · 1 comment
Labels
enhancement New feature or request p2

Comments

@mikeldking
Copy link
Contributor

mikeldking commented Feb 8, 2024

Feature Description

As a user of LlamaIndex in a production setting, I may want to tag or add metadata to a queryEngine or invocation.

E.x. I have a queryEngine that serves a specific topic, I want to add user metadata to the query such as country of origin.

This metadata and or tags would then be made available to the callback system such that tracing solutions (such as arize-phoenix, LangFuse, Traceloop) can properly annotate the spans with these attributes for audits and cohort analysis.

LangChain reference

LangChain supports this capability natively in their chain abstractions.

example

 prompt_template = "Tell me a {adjective} joke"
 prompt = PromptTemplate(input_variables=["adjective"], template=prompt_template)
 llm = LLMChain(llm=OpenAI(), prompt=prompt, metadata={"category": "jokes"})
 completion = llm.predict(adjective="funny", metadata={"variant": "funny"})

Related community asks:

Screenshot 2024-02-08 at 10 46 38 AM

Reason

For production observability and monitoring of cohorts, filtering of traces and inferences by user and application-defined annotations

Value of Feature

Observability in production, troubleshooting, automatic labeling to be piped into evals, etc.

@mikeldking mikeldking added enhancement New feature or request triage Issue needs to be triaged/prioritized labels Feb 8, 2024
Copy link

dosubot bot commented Feb 8, 2024

🤖

Thank you for your feature request. I understand that you would like to add metadata to a queryEngine or invocation in LlamaIndex, similar to the capability in LangChain. This metadata would then be made available to the callback system for better observability in production, troubleshooting, and automatic labeling.

Currently, LlamaIndex does support adding metadata to the queryEngine and invocations. This is evident from the metadata_mode parameter in the CitationQueryEngine class's __init__ method and from_args class method. The metadata_mode parameter is an instance of the MetadataMode class, which controls how metadata is included in the citation prompt. You can find the relevant code in the CitationQueryEngine class.

However, to make this metadata available to the callback system, you would need to create new event types for them in the CBEventType enumeration. Then, you can use the on_event_start and on_event_end methods to handle these events, passing the metadata as the payload argument. Here is an example of how you can add metadata to a queryEngine event:

from llama_index.callbacks.schema import CBEventType

# Define your metadata
query_engine_metadata = {
    'engine_id': 'engine_1',
    'engine_type': 'type_1',
    # Add more metadata as needed
}

# Start the queryEngine event
event_id = callback_manager.on_event_start(
    CBEventType.QUERY_ENGINE,  # Assuming QUERY_ENGINE is a new event type you added
    payload=query_engine_metadata
)

# ... Perform the queryEngine operations ...

# End the queryEngine event
callback_manager.on_event_end(
    CBEventType.QUERY_ENGINE,
    payload=query_engine_metadata,
    event_id=event_id
)

This will make the metadata available to the callback system, which can be used for better observability in production, troubleshooting, and automatic labeling. You can find more about this in the CallbackManager class.

Please note that this is a high-level suggestion and the actual implementation may vary based on your specific use case and the current structure of your code. If you need further assistance, feel free to ask.

Sources

About Dosu

This response is meant to be useful and save you time. It is not meant to be a precise solution, but rather a starting point for your own research.

Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant.

If you want to continue the conversation, start your reply with @dosu-bot.

@logan-markewich logan-markewich added P1 p2 and removed P1 triage Issue needs to be triaged/prioritized labels Feb 8, 2024
@dosubot dosubot bot added the stale Issue has not had recent activity or appears to be solved. Stale issues will be automatically closed label May 9, 2024
@dosubot dosubot bot closed this as not planned Won't fix, can't repro, duplicate, stale May 16, 2024
@dosubot dosubot bot removed the stale Issue has not had recent activity or appears to be solved. Stale issues will be automatically closed label May 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request p2
Projects
None yet
Development

No branches or pull requests

2 participants