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

Implement embeddings for use with LLM agents #680

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

ahuang11
Copy link
Contributor

@ahuang11 ahuang11 commented Aug 21, 2024

Uses duckdb instead of chromadb. Currently subsets embeddings by table name. Not sure how to handle ephemeral tables yet.

image
import io
import asyncio

import lumen.ai as lmai
import panel as pn
import pandas as pd

from lumen.sources.duckdb import DuckDBSource
from lumen.ai.analysis import Join

pn.extension(
    "tabulator",
    "codeeditor",
    "vega",
    inline=False,
    template="fast",
    notifications=True,
)

llm = lmai.llm.OpenAI(
    # interceptor_path="interceptor.db"
)

embeddings = lmai.embeddings.OpenAIEmbeddings.from_dict(
    {
        "windturbines.parquet": [
            "The creator of this dataset is named Andrew HH",
            "To run the imaginary, test analysis, simply divide turbine count by 3",
        ]
    }
)

cs = lmai.memory["current_source"] = DuckDBSource(
    tables=["windturbines.parquet"],
    uri=":memory:",
    initializers=["INSTALL httpfs;", "LOAD httpfs;"],
)

custom_agent = lmai.agents.AnalysisAgent(analyses=[Join])

assistant = lmai.Assistant(
    llm=llm,
    agents=[
        lmai.agents.SourceAgent,
        lmai.agents.TableAgent,
        lmai.agents.TableListAgent,
        lmai.agents.SQLAgent,
        lmai.agents.PipelineAgent,
        lmai.agents.hvPlotAgent,
        lmai.agents.ChatAgent,
        custom_agent,
    ],
    embeddings=embeddings,
    suggestions=["Who is the creator of this dataset?"],
)
assistant.servable("Lumen.ai")
assistant.controls().servable(area="sidebar")

Copy link

codecov bot commented Aug 21, 2024

Codecov Report

Attention: Patch coverage is 0% with 69 lines in your changes missing coverage. Please review.

Project coverage is 56.40%. Comparing base (2622c0b) to head (58b32fd).
Report is 19 commits behind head on main.

Files Patch % Lines
lumen/ai/embeddings.py 0.00% 57 Missing ⚠️
lumen/ai/agents.py 0.00% 6 Missing ⚠️
lumen/ai/assistant.py 0.00% 6 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #680      +/-   ##
==========================================
- Coverage   57.03%   56.40%   -0.64%     
==========================================
  Files          98       98              
  Lines       11598    11737     +139     
==========================================
+ Hits         6615     6620       +5     
- Misses       4983     5117     +134     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@ahuang11 ahuang11 marked this pull request as ready for review August 28, 2024 02:32
@ahuang11 ahuang11 changed the title Start refactoring embeddings Implement embeddings for use with LLM agents Aug 28, 2024
text = "\n".join([message["content"] for message in messages])
# TODO: refactor this so it's not subsetting by index
# [(0, 'The creator of this dataset is named Andrew HH', 0.7491879463195801, 'windturbines.parquet')]
result = self.embeddings.query(text, table_name=table_name)[0][1]
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Another TODO: handle ephemeral tables

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.

1 participant