And get started streamlining your processes for working with higher-order networks from start to finish! XGI is part of the #pyOpenSci ecosystem, and excels at many things, including:
🔍 Analyzing higher-order networks with measures and algorithms
🧰 Manipulating node and edge statistics in a flexible and customizable way
🎨 Drawing higher-order networks in a variety of visually striking ways
I was up late trying to figure out a stupid issue I was having with the Crowdstrike API so I didn't stream on twitch last night, hoping to do a stream tonight. I think they took a feature out my team was actually using which would allow me to contain a device and make a note that could be viewed in the dashboard.
Back in January, we started looking at AI and how to run a large language model (LLM) locally (instead of just using something like ChatGPT or Gemini). A tool like Ollama is great for building a system that uses AI without dependence on OpenAI. Today, we will look at creating a Retrieval-augmented generation (RAG) application, using Python, LangChain, Chroma DB, and Ollama. Retrieval-augmented generation is the process of optimizing the output of a large language model, so it references an authoritative knowledge base outside of its training data sources before generating a response. If you have a source of truth that isn’t in the training data, it is a good way to get the model to know about it. Let’s get started!
Your RAG will need a model (like llama3 or mistral), an embedding model (like mxbai-embed-large), and a vector database. The vector database contains relevant documentation to help the model answer specific questions better. For this demo, our vector database is going to be Chroma DB. You will need to “chunk” the text you are feeding into the database. Let’s start there.
Chunking
There are many ways of choosing the right chunk size and overlap but for this demo, I am just going to use a chunk size of 7500 characters and an overlap of 100 characters. I am also going to use LangChain‘s CharacterTextSplitter to do the chunking. It means that the last 100 characters in the value will be duplicated in the next database record.
The Vector Database
A vector database is a type of database designed to store, manage, and manipulate vector embeddings. Vector embeddings are representations of data (such as text, images, or sounds) in a high-dimensional space, where each data item is represented as a dense vector of real numbers. When you query a vector database, your query is transformed into a vector of real numbers. The database then uses this vector to perform similarity searches.
You can think of it as being like a two-dimensional chart with points on it. One of those points is your query. The rest are your database records. What are the points that are closest to the query point?
Our main model for this demo is going to be phi3. It is a 3.8B parameters model that was trained by Microsoft.
LangChain
You will notice that today’s demo is heavily using LangChain. LangChain is an open-source framework designed for developing applications that use LLMs. It provides tools and structures that enhance the customization, accuracy, and relevance of the outputs produced by these models. Developers can leverage LangChain to create new prompt chains or modify existing ones. LangChain pretty much has APIs for everything that we need to do in this app.
The Actual App
Before we start, you are going to want to pip install tiktoken langchain langchain-community langchain-core. You are also going to want to ollama pull phi3 and ollama pull nomic-embed-text. This is going to be a CLI app. You can run it from the terminal like python3 app.py "<Question Here>".
You also need a sources.txt file containing the URLs of things that you want to have in your vector database.
The May 7th event is too recent to be in the model’s training data. This makes sure that the model knows about it. You could also feed the model company policy documents, the rules to a board game, or your diary and it will magically know that information. Since you are running the model in Ollama, there is no risk of that information getting out, too. It is pretty awesome.
Have any questions, comments, etc? Feel free to drop a comment, below.
Django peeps. I want to link my languages table (English, French, Chinese, etc) to the word classes (Nouns, Verbs, Adjectives, etc) table. It would be a many-to-many relationship, but I'm not sure whether to use a join table or the many-to-many model. What's the most Django way?
Woah! I’m giving a talk at #PyConUS titled “Paint by Numbers: A Retrospective on the ‘NumPy Comics’ and Under-Represented Skillsets in Documentation”.
A refreshingly honest tell-all on what went right, what went wrong and what went horribly wrong. 🥲 Check it out at the Documentation Summit, Sunday, May 19!
> "#Python 3.13 just hit feature freeze with the first beta release today. Just before the feature freeze, a shiny new feature was added: a brand new Python REPL."
This is the first time I work for a company that I actively want to personally advertise for, but I really like what #Grist does. It's like a #spreadsheet that's really a #database and lets you use #Python as a computational language. And it's all open source!
I just saw someone ask "why do I have to prepend a dot to import a file in the same directory?"
That depends on whether the file with the import statement is in a package or not.
But, whether Python considers it to be in a package depends on how you imported (or ran) that file. You can't determine it from the file's content or the filesystem structure!
Check alt text (image description) for explanations of the examples.
Google fired their Python team, including one of our pybind11 lead developers (the list of accomplishments of that team is, ah, was, impressive!) We'll need to tighten up our min version support for pybind11, so I've opened up a poll: https://github.com/pybind/pybind11/discussions/5124 3.7+ or 3.8+? #python
#python fixture config is magic and I don't like it.
def test_something(fixture):
...
So in pytest. What this does is get the name of the param fixture to see if it matches the name of a previously defined fixture function. If you don't know that it looks bizarre. That IS NOT a parameter passed into a function but a sentinel that is used to look up a fixture by it's parameter name.