diff --git a/.devcontainer/dev/Dockerfile b/.devcontainer/dev/Dockerfile index 77a1c0bae446..dd46421a06a3 100644 --- a/.devcontainer/dev/Dockerfile +++ b/.devcontainer/dev/Dockerfile @@ -24,7 +24,9 @@ RUN git clone https://github.com/autogen-ai/autogen.git /home/autogen-ai/autogen WORKDIR /home/autogen-ai/autogen # Install AutoGen in editable mode with extra components -RUN sudo pip install -e .[test,teachable,lmm,retrievechat,mathchat,blendsearch] +RUN sudo pip install --upgrade pip && \ + sudo pip install -e .[test,teachable,lmm,retrievechat,mathchat,blendsearch] && \ + pip install pytest-xdist pytest-cov # Install pre-commit hooks RUN pre-commit install @@ -47,7 +49,6 @@ ENV PATH="${PATH}:/home/autogen-ai/quarto/quarto-1.5.23/bin/" EXPOSE 3000 # Pre-load popular Python packages -RUN pip install --upgrade pip RUN pip install numpy pandas matplotlib seaborn scikit-learn requests urllib3 nltk pillow pytest beautifulsoup4 # Set the default command to bash diff --git a/.devcontainer/full/Dockerfile b/.devcontainer/full/Dockerfile index 043db71b368f..7fb38e416f5f 100644 --- a/.devcontainer/full/Dockerfile +++ b/.devcontainer/full/Dockerfile @@ -23,7 +23,7 @@ WORKDIR /home/autogen-ai # Install Python packages RUN pip install --upgrade pip RUN pip install autogen[teachable,lmm,retrievechat,mathchat,blendsearch] autogenra -RUN pip install numpy pandas matplotlib seaborn scikit-learn requests urllib3 nltk pillow pytest beautifulsoup4 +RUN pip install numpy pandas matplotlib seaborn scikit-learn requests urllib3 nltk pillow pytest beautifulsoup4 pytest-xdist pytest-cov # Expose port EXPOSE 8081 diff --git a/.github/workflows/contrib-graph-rag-tests.yml b/.github/workflows/contrib-graph-rag-tests.yml new file mode 100644 index 000000000000..2df2d3c93a43 --- /dev/null +++ b/.github/workflows/contrib-graph-rag-tests.yml @@ -0,0 +1,66 @@ +# This workflow will install Python dependencies, run tests and lint with a variety of Python versions +# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions + +name: ContribGraphRagTests + +on: + pull_request: + branches: ["main"] + paths: + - "autogen/agentchat/contrib/graph_rag/**" + - "test/agentchat/contrib/graph_rag/**" + - ".github/workflows/contrib-tests.yml" + - "setup.py" + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }}-${{ github.head_ref }} + cancel-in-progress: ${{ github.ref != 'refs/heads/main' }} +permissions: + {} + # actions: read + # checks: read + # contents: read + # deployments: read +jobs: + GraphRagIntegrationTest-FalkorDB-Ubuntu: + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + python-version: ["3.10", "3.11"] + services: + falkordb: + image: falkordb/falkordb:edge + ports: + - 6379:6379 + steps: + - uses: actions/checkout@v4 + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v5 + with: + python-version: ${{ matrix.python-version }} + - name: Install packages and dependencies for all tests + run: | + python -m pip install --upgrade pip wheel + pip install pytest + - name: Install Falkor DB SDK when on linux + run: | + pip install -e .[graph_rag_falkor_db] + - name: Set AUTOGEN_USE_DOCKER based on OS + shell: bash + run: | + echo "AUTOGEN_USE_DOCKER=False" >> $GITHUB_ENV + - name: Coverage + env: + OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }} + AZURE_OPENAI_API_KEY: ${{ secrets.AZURE_OPENAI_API_KEY }} + AZURE_OPENAI_API_BASE: ${{ secrets.AZURE_OPENAI_API_BASE }} + OAI_CONFIG_LIST: ${{ secrets.OAI_CONFIG_LIST }} + run: | + pip install pytest-cov>=5 + pytest test/agentchat/contrib/graph_rag/test_falkor_graph_rag.py --skip-openai + - name: Upload coverage to Codecov + uses: codecov/codecov-action@v3 + with: + file: ./coverage.xml + flags: unittests diff --git a/autogen/agentchat/contrib/graph_rag/falkor_graph_query_engine.py b/autogen/agentchat/contrib/graph_rag/falkor_graph_query_engine.py new file mode 100644 index 000000000000..0bb1f51a05b3 --- /dev/null +++ b/autogen/agentchat/contrib/graph_rag/falkor_graph_query_engine.py @@ -0,0 +1,76 @@ +import os +from dataclasses import field +from typing import List + +from graphrag_sdk import KnowledgeGraph, Source +from graphrag_sdk.schema import Schema + +from .document import Document +from .graph_query_engine import GraphStoreQueryResult + + +class FalkorGraphQueryResult(GraphStoreQueryResult): + messages: list = field(default_factory=list) + + +class FalkorGraphQueryEngine: + """ + This is a wrapper for Falkor DB KnowledgeGraph. + """ + + def __init__( + self, + name: str, + host: str = "127.0.0.1", + port: int = 6379, + username: str | None = None, + password: str | None = None, + model: str = "gpt-4-1106-preview", + schema: Schema | None = None, + ): + """ + Initialize a Falkor DB knowledge graph. + Please also refer to https://github.com/FalkorDB/GraphRAG-SDK/blob/main/graphrag_sdk/kg.py + + Args: + name (str): Knowledge graph name. + host (str): FalkorDB hostname. + port (int): FalkorDB port number. + username (str|None): FalkorDB username. + password (str|None): FalkorDB password. + model (str): OpenAI model to use for Falkor DB to build and retrieve from the graph. + schema: Falkor DB knowledge graph schema (ontology), https://github.com/FalkorDB/GraphRAG-SDK/blob/main/graphrag_sdk/schema/schema.py + If None, Falkor DB will auto generate a schema from the input docs. + """ + self.knowledge_graph = KnowledgeGraph(name, host, port, username, password, model, schema) + + def init_db(self, input_doc: List[Document] | None): + """ + Build the knowledge graph with input documents. + """ + sources = [] + for doc in input_doc: + if os.path.exists(doc.path_or_url): + sources.append(Source(doc.path_or_url)) + + if sources: + self.knowledge_graph.process_sources(sources) + + def add_records(self, new_records: List) -> bool: + raise NotImplementedError("This method is not supported by Falkor DB SDK yet.") + + def query(self, question: str, n_results: int = 1, **kwargs) -> FalkorGraphQueryResult: + """ + Query the knowledage graph with a question and optional message history. + + Args: + question: a human input question. + n_results: number of returned results. + kwargs: + messages: a list of message history. + + Returns: FalkorGraphQueryResult + """ + messages = kwargs.pop("messages", []) + answer, messages = self.knowledge_graph.ask(question, messages) + return FalkorGraphQueryResult(answer=answer, results=[], messages=messages) diff --git a/autogen/agentchat/contrib/graph_rag/graph_query_engine.py b/autogen/agentchat/contrib/graph_rag/graph_query_engine.py index 28ef6ede84a6..ca29fa165cde 100644 --- a/autogen/agentchat/contrib/graph_rag/graph_query_engine.py +++ b/autogen/agentchat/contrib/graph_rag/graph_query_engine.py @@ -34,7 +34,6 @@ def init_db(self, input_doc: List[Document] | None = None): Args: input_doc: a list of input documents that are used to build the graph in database. - Returns: GraphStore """ pass diff --git a/autogen/version.py b/autogen/version.py index 91b26580a39f..f013a5c62a02 100644 --- a/autogen/version.py +++ b/autogen/version.py @@ -4,4 +4,4 @@ # # Portions derived from https://github.com/microsoft/autogen are under the MIT License. # SPDX-License-Identifier: MIT -__version__ = "0.3.0" +__version__ = "0.3.1" diff --git a/setup.py b/setup.py index 380687758862..4ca0587e7412 100644 --- a/setup.py +++ b/setup.py @@ -59,6 +59,10 @@ retrieve_chat_pgvector = [*retrieve_chat, "pgvector>=0.2.5"] +graph_rag_falkor_db = [ + "graphrag_sdk", +] + if current_os in ["Windows", "Darwin"]: retrieve_chat_pgvector.extend(["psycopg[binary]>=3.1.18"]) elif current_os == "Linux": @@ -81,6 +85,7 @@ "retrievechat-pgvector": retrieve_chat_pgvector, "retrievechat-mongodb": [*retrieve_chat, "pymongo>=4.0.0"], "retrievechat-qdrant": [*retrieve_chat, "qdrant_client", "fastembed>=0.3.1"], + "graph_rag_falkor_db": graph_rag_falkor_db, "autobuild": ["chromadb", "sentence-transformers", "huggingface-hub", "pysqlite3"], "teachable": ["chromadb"], "lmm": ["replicate", "pillow"], diff --git a/test/agentchat/contrib/graph_rag/test_falkor_graph_rag.py b/test/agentchat/contrib/graph_rag/test_falkor_graph_rag.py new file mode 100644 index 000000000000..8814479da9a1 --- /dev/null +++ b/test/agentchat/contrib/graph_rag/test_falkor_graph_rag.py @@ -0,0 +1,61 @@ +import sys + +import pytest +from conftest import reason, skip_openai # noqa: E402 +from graphrag_sdk import KnowledgeGraph, Source +from graphrag_sdk.schema import Schema + +try: + from autogen.agentchat.contrib.graph_rag.document import ( + Document, + DocumentType, + ) + from autogen.agentchat.contrib.graph_rag.falkor_graph_query_engine import ( + FalkorGraphQueryEngine, + GraphStoreQueryResult, + ) +except ImportError: + skip = True +else: + skip = False + +reason = "do not run on MacOS or windows OR dependency is not installed OR " + reason + + +@pytest.mark.skipif( + sys.platform in ["darwin", "win32"] or skip or skip_openai, + reason=reason, +) +def test_falkor_db_query_engine(): + """ + Test Falkor DB Query Engine. + 1. create a test Falkor DB Query Engine with a schema. + 2. Initialize it with an input txt file. + 3. Query it with a question and verify the result contains the critical information. + """ + # Arrange + test_schema = Schema() + actor = test_schema.add_entity("Actor").add_attribute("name", str, unique=True) + movie = test_schema.add_entity("Movie").add_attribute("title", str, unique=True) + test_schema.add_relation("ACTED", actor, movie) + + query_engine = FalkorGraphQueryEngine(schema=test_schema) + + source_file = "test/agentchat/contrib/graph_rag/the_matrix.txt" + input_docs = [Document(doctype=DocumentType.TEXT, path_or_url=source_file)] + + question = "Name a few actors who've played in 'The Matrix'" + + # Act + query_engine.init_db(input_doc=input_docs) + + query_result: GraphStoreQueryResult = query_engine.query(question=question) + + # Assert + assert query_result.answer.find("Keanu Reeves") >= 0 + for message in query_result.messages: + if isinstance(message, dict) and "role" in message and message["role"] == "user": + assert "content" in message + assert message["content"] is question + return + pytest.fail("Question not found in message history.") diff --git a/test/agentchat/contrib/graph_rag/the_matrix.txt b/test/agentchat/contrib/graph_rag/the_matrix.txt new file mode 100644 index 000000000000..3f155218af3c --- /dev/null +++ b/test/agentchat/contrib/graph_rag/the_matrix.txt @@ -0,0 +1,415 @@ +Signed in +Skip to Main Content + Rotten Tomatoes + +What's the Tomatometer®? +Critics +MOVIES TV SHOWS SHOP NEW NEWS SHOWTIMES +TRENDING ON RT +Furiosa First Reviews +Most Anticipated 2025 Movies +Best Movies of All Time +TV Premiere Dates +Main image for The Matrix +The Matrix +R, Now Playing, 2h 16m, Sci-Fi/ Action + + LIST +Videos +Rotten Tomatoes is Wrong About... The Matrix Sequels +51:31 +Rotten Tomatoes is Wrong About... The Matrix Sequels +Content collapsed. +‘The Matrix’ Government Lobby Scene | Rotten Tomatoes’ 21 Most Memorable Moments +2:31 +‘The Matrix’ Government Lobby Scene | Rotten Tomatoes’ 21 Most Memorable Moments +Content collapsed. +View more videos +movie poster +Tomatometer +207 Reviews +Audience Score +250,000+ Ratings +Neo (Keanu Reeves) believes that Morpheus (Laurence Fishburne), an elusive figure considered to be the most dangerous man alive, can answer his question -- What is the Matrix? Neo is contacted by Trinity (Carrie-Anne Moss), a beautiful stranger who leads him into an underworld where he meets Morpheus. They fight a brutal battle for their lives against a cadre of viciously intelligent secret agents. It is a truth that could cost Neo something more precious than his life. +Content collapsed. +Read More +fandango +Now in Theaters +Now Playing +Buy tickets for The Matrix +Where to Watch +What to Know +Reviews +Cast & Crew +More Like This +Related News +Videos +Photos +Media Info + +Next +Where To Watch +The Matrix +fandango +In Theaters +vudu +Fandango at Home +amazon-prime-video-us +Prime Video +netflix +Netflix +Watch The Matrix with a subscription on Netflix, rent on Fandango at Home, Prime Video, or buy on Fandango at Home, Prime Video. +The Matrix +What To Know + Critics Consensus +Thanks to the Wachowskis' imaginative vision, The Matrix is a smartly crafted combination of spectacular action and groundbreaking special effects. + +Read Critics Reviews +Critics Reviews +View All (207) Critics Reviews + Critic's profile +Critic's Name +Mike Clark +Publication +USA Today +TOP CRITIC +The review +Though The Matrix ultimately overdoses on gloom-and-doom grunge, over-elaborate cool and especially running time, it's just clever enough to enable [the Wachowskis] to nix the sophomore jinx following 1996's Bound. +Content collapsed. +Fresh score. +Rated: 2.5/4 • +Date +Jul 13, 2023 +Full Review + Critic's profile +Critic's Name +Joe Morgenstern +Publication +Wall Street Journal +TOP CRITIC +The review +I know almost nothing of the intricate techniques that make The Matrix as eye-filling as it is brain-numbing, but I can tell you that... [its visuals] are wondrous to behold. +Content collapsed. +Fresh score. +Date +Jul 13, 2023 +Full Review + Critic's profile +Critic's Name +Manohla Dargis +Publication +L.A. Weekly +TOP CRITIC +The review +There's more form than content in The Matrix, but Bill Pope's swooping, noir-inflected cinematography is wonderfully complemented by Owen Paterson's inventive production design, a great soundtrack and the best fight choreography this side of Hong Kong. +Content collapsed. +Fresh score. +Date +Jul 13, 2023 +Full Review + Critic's profile +Critic's Name +Sean Axmaker +Publication +Stream on Demand +The review +The Wachowskis proceed to turn the world as we know it into a virtual reality landscape with a 20th century tech-noir look (lit with a sickly green hue, like the glow of an old IBM computer screen) and the physics of a video game. +Content collapsed. +Fresh score. +Date +Sep 9, 2023 +Full Review + Critic's profile +Critic's Name +Dan DiNicola +Publication +The Daily Gazette (Schenectady, NY) +The review +A $60 million, high-tech assault on the senses and a pretentious insult to the mind. +Content collapsed. +Rotten score. +Date +Jul 15, 2023 +Full Review + Critic's profile +Critic's Name +Christopher Brandon +Publication +TNT's Rough Cut +The review +A cyberpunk thriller that's so much fun to watch, it could single-handedly reboot the genre. +Content collapsed. +Fresh score. +Date +Jul 13, 2023 +Full Review +Read all reviews + +Next +Audience Reviews +View All (1000+) audience reviews +Critic's Name +casearmitage +The review +Twenty five years later, it still holds up. You have to see it to believe it. +Content collapsed. +Rated 5/5 Stars • Rated 5 out of 5 stars +Date +04/04/24 +Full Review +Critic's Name +Nathanael +The review +Of course The Matrix is absolutely amazing, but the 4DX thing was pretty cool too! +Content collapsed. +Rated 5/5 Stars • Rated 5 out of 5 stars +Date +12/14/21 +Full Review +Critic's Name +Average P +The review +So good that you entirely forget the nutty premise that we're all being kept in suspended animation wired into some kind of giant mainframe which creates more energy than it requires. Oh well, whatever. Great adventure story. +Content collapsed. +Rated 5/5 Stars • Rated 5 out of 5 stars +Date +05/23/24 +Full Review +Critic's Name +First name L +The review +Event cinema in at it's best, it's often mocked, equally celebrated, for a reason. +Content collapsed. +Rated 4/5 Stars • Rated 4 out of 5 stars +Date +05/14/24 +Full Review +Critic's Name +Jace E +The review +The Matrix is one of the most ambitious and captivating Sci-Fi films of all time. The action is electric, the characters are strong and there are legendary moments peppered throughout. Where the film is lacking is in the actual human aspect; the romance is underdeveloped and Neo's life in the Matrix is superficial (why do we need a scene of his boss disciplining him?). That being said, the fight sequences are incredibly entertaining and the entire idea of the Matrix plays with your mind. I honestly fell asleep multiple times watching the film and had to go back and watch it again. From the slow motion to the muted colors, it was easy to doze off. However, once the climactic moments hit, I was enthralled. The helicopter scene is great and the final fight sequences hit hard. I'm curious where the franchise will go from here, but this film is a brilliant start. Best Character: Tank Best Quote: "There's a difference between knowing the path and walking the path." - Morpheus Best Scene: The Bullet Dodge Best Piece of Score: "He's the One Alright" +Content collapsed. +Rated 4/5 Stars • Rated 4 out of 5 stars +Date +05/13/24 +Full Review +Critic's Name +Antonio M +The review +Ha fatto la storia del cinema cyberpunk. Un cult intramontabile. +Content collapsed. +Rated 5/5 Stars • Rated 5 out of 5 stars +Date +05/09/24 +Full Review +Read all reviews + +Next +Cast & Crew +Lilly Wachowski thumbnail image +Lilly Wachowski +Director + Lana Wachowski thumbnail image +Lana Wachowski +Director + Keanu Reeves thumbnail image +Keanu Reeves +Thomas A. Anderson + Laurence Fishburne thumbnail image +Laurence Fishburne +Morpheus + Carrie-Anne Moss thumbnail image +Carrie-Anne Moss +Trinity + Hugo Weaving thumbnail image +Hugo Weaving +Agent Smith +Content collapsed. +Show More Cast & Crew +More Like This +View All Movies in Theaters + The Matrix Reloaded poster +Certified fresh score. +74% +Fresh audience score. +72% +The Matrix Reloaded + + WATCHLIST +The Matrix Revolutions poster +Rotten score. +34% +Fresh audience score. +60% +The Matrix Revolutions + + WATCHLIST +Demolition Man poster +Fresh score. +63% +Fresh audience score. +67% +Demolition Man + + WATCHLIST +Universal Soldier: The Return poster +Rotten score. +5% +Rotten audience score. +24% +Universal Soldier: The Return + + WATCHLIST +Terminator 3: Rise of the Machines poster +Fresh score. +70% +Rotten audience score. +46% +Terminator 3: Rise of the Machines + + WATCHLIST + +Discover more movies and TV shows. +View More + +Next +Related Movie News +View All Related Movie News + +25 Memorable Movie Lines of the Last 25 Years +Content collapsed. + +Sterling K. Brown’s Five Favorite Films +Content collapsed. + +The Matrix vs. John Wick +Content collapsed. + +Next +Videos +View All videos +The Matrix +Rotten Tomatoes is Wrong About... The Matrix Sequels +51:31 +Rotten Tomatoes is Wrong About... The Matrix Sequels +Content collapsed. +‘The Matrix’ Government Lobby Scene | Rotten Tomatoes’ 21 Most Memorable Moments +2:31 +‘The Matrix’ Government Lobby Scene | Rotten Tomatoes’ 21 Most Memorable Moments +Content collapsed. +View more videos + +Next +Photos +View All The Matrix photos +The Matrix + +The Matrix photo 1 + +The Matrix photo 2 + +The Matrix photo 3 + +The Matrix photo 4 + +Anthony Ray Parker as Dozer, Keanu Reeves as Thomas A. Anderson/Neo, Carrie-Anne Moss as Trinity, and Laurence Fishburne as Morpheus in Nebuchadnezzer's cockpit. + +Keanu Reeves and Carrie-Anne Moss in Warner Brothers' The Matrix. + +Laurence Fishburne in Warner Brothers' The Matrix + +Carrie-Anne Moss and Keanu Reeves in Warner Brothers' The Matrix + +Carrie-Anne Moss in Warner Brothers' The Matrix + +Keanu Reeves in Warner Brothers' The Matrix +View more photos + +Next +Movie Info +Synopsis +Neo (Keanu Reeves) believes that Morpheus (Laurence Fishburne), an elusive figure considered to be the most dangerous man alive, can answer his question -- What is the Matrix? Neo is contacted by Trinity (Carrie-Anne Moss), a beautiful stranger who leads him into an underworld where he meets Morpheus. They fight a brutal battle for their lives against a cadre of viciously intelligent secret agents. It is a truth that could cost Neo something more precious than his life. +Director +Lilly Wachowski , Lana Wachowski +Producer +Joel Silver +Screenwriter +Lilly Wachowski , Lana Wachowski +Distributor +Warner Bros. Pictures +Production Co +Silver Pictures , Village Roadshow Prod. +Rating +R (Sci-Fi Violence|Brief Language) +Genre +Sci-Fi , Action +Original Language +English +Release Date (Theaters) +Mar 31, 1999, Wide +Rerelease Date (Theaters) +Sep 22, 2023 +Release Date (Streaming) +Jan 1, 2009 +Box Office (Gross USA) +$171.4M +Runtime +2h 16m +Sound Mix +Dolby Stereo , DTS , SDDS , Surround , Dolby Digital , Dolby SR +Aspect Ratio +Scope (2.35:1) +What to Watch +In Theaters +At Home +TV Shows +Now Playing +VIEW ALL NOW PLAYING +No score yet. +The Keeper +- - +Certified fresh score. +The Crow +85% +No score yet. +The Commandant's Shadow +- - +No score yet. +The Hangman +- - +Certified fresh score. +In A Violent Nature +90% +Fresh score. +Ezra +75% +Coming soon +VIEW ALL COMING SOON +No score yet. +Jesus Thirsts: The Miracle of the Eucharist +- - +No score yet. +Queen Tut +- - +No score yet. +The Watchers +- - +No score yet. +Bad Boys: Ride or Die +- - +Advertise With Us +Help +About Rotten Tomatoes +What's the Tomatometer®? +Critic Submission +Licensing +Advertise With Us +Careers +JOIN THE NEWSLETTER + +Get the freshest reviews, news, and more delivered right to your inbox! + +FOLLOW US + +V3.1 Privacy Policy Terms and Policies Cookie Notice California Notice Ad Choices Accessibility +Copyright © Fandango. All rights reserved.