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 5 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 27.14286% with 51 lines in your changes missing coverage. Please review.

Project coverage is 60.70%. Comparing base (73fda79) to head (18dfbf5).

Files with missing lines Patch % Lines
lumen/ai/embeddings.py 29.82% 40 Missing ⚠️
lumen/ai/agents.py 0.00% 7 Missing ⚠️
lumen/ai/assistant.py 33.33% 4 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #680      +/-   ##
==========================================
- Coverage   60.82%   60.70%   -0.12%     
==========================================
  Files         100      100              
  Lines       12402    12445      +43     
==========================================
+ Hits         7543     7555      +12     
- Misses       4859     4890      +31     

☔ 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

lumen/ai/agents.py Outdated Show resolved Hide resolved
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