Skip to content

Instantly share code, notes, and snippets.

Graph RAG information (Neo4J, LlamaIndex, Groq API)

What follows is a conversation I had with Anthropic's https://claude.ai/ LLM, asking it questions about how Graph RAG works in as much detail as I could think of. When I think of graph databases, I normally think RDF, but the generally preferred graph DB for LLM apps seems to be Neo4J which uses a query language called Cypher rather than SPARQL, so there are some questions below about Neo4J and Cypher syntax. The thing I really wanted to know about was the sequence of queries and responses involved, and how the queries are constructed, and how the responses are interpreted.

Prompt:

During a typical graph rag query and response, what would a langsmith trace look like?

@wware
wware / local_logger.py
Created October 4, 2024 15:38
I once fooled with a flavor of local loggers (actually I called them "topical loggers") that I ended up not liking. Here the name is automatically derived from the source filename so there's less to keep track of. Maybe I'll like this approach better. Environment variables are used to decide who gets DEBUG-level logging, otherwise it's INFO-level.
# This first piece can go into some global utils.py file.
# python foo.py
# LOGGER_FOO_PY=DEBUG python foo.py
# python -m pytest foo.py
import logging
import os
import inspect
import pytest
from unittest.mock import patch
@wware
wware / RDF_Scholar_Readme.md
Last active November 13, 2023 21:22
This is a README for a GPT I'm working on

RDF Scholar

RDF Scholar is a specialized AI designed to assist in converting scientific text into Turtle/RDF format. This is particularly useful for enhancing the machine-readability of scientific literature. It leverages various ontologies, such as ModSci and PharmSci, and aligns with resources like the Semantic Web for Life Sciences to ensure that the RDF outputs are accurate and semantically rich. The goal is to facilitate the organization, sharing, and discovery of scientific knowledge through structured data. My functionalities

@wware
wware / literate_asserts.py
Last active July 29, 2023 04:27
A "literate" assert is one that tries to clarify better what's going on in some code that might be otherwise unclear.
"""
More detailed explanatory asserts can help to clarify code and provide
a narrative about what's going on, what is intended or expected, etc.
So a message might look like this.
Notify {name} that the errno is {errno}.
and object attributes are
foo.a = {foo.a}
foo.b = {foo.b}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@wware
wware / lp_hacks.md
Created April 15, 2022 18:21
A bit of fun with literate programming using Markdown

Literate Programming hacks

Let's try some literate programming. From Don Knuth's original idea, thru Norman Ramsey's noweb reformulation, by way of Jonathan Aquino's Python version, which I tweaked to accept Markdown input and added a few new features.

$ ./noweb.py -R 'outer function' lp_hacks.md | python
Hello world
"""
I've modified John Gaines Jr.'s answer to handle lists. I didn't need editing
or the Taglist for what I'm doing so I removed them. They could certainly be
added back. Since lists can introduce duplication of keys, I replaced the keys
with UUIDs while still showing the original key as text on the left side of the
treeview.
UPDATE: My original answer did not include the editing function that John Gaines Jr.
had implemented. I've now added that to mine, with the caveat that I'm not very
expert regarding Tk/Tkinter layout and spacing, so I stopped tinkering once it
import os
import linecache
import pprint
import sys
from functools import wraps
class IncludeExclude(object):
def __init__(self, inclusions=None, exclusions=None):
self._inclusions = inclusions

Making X Windows work for a Docker container

https://stackoverflow.com/questions/49169055

This is because the container couldn't access the x11 socket of the host. so when doing the docker run, need to include these two flag.

-v /tmp/.X11-unix:/tmp/.X11-unix
-e DISPLAY=unix$DISPLAY

and after this, we need to do another operation. because the default settings of X11 only allows local users to print. so we need to change this to all users.

#!/usr/bin/env python
"""
To run these tests remotely with Ansible, add command line arguments:
./ansible_unit_tests.py -i inventory.yaml hostname
./ansible_unit_tests.py -i inventory.yaml group
To convert docstrings into a Markdown file, type: