Tutorial: PostgreSQL Assistant
In a few steps we will show you how to create a RAG application using Needle.
- Step 1: You will create a collection in Needle and add the PostgreSQL documentation to it.
- Step 2: We will show you how to track the status of the collection.
- Step 3: How to perform a search in the collection.
- Bonus step: Compose an answer from the search results.
Intro
We love working with PostgreSQL, we use it for our own projects and we know that many of you do too. It packs in so many features that it can be hard to keep track of them all - for our human brains!
That's why it makes sense to create an assistant specifically tailored towards PostgreSQL. Without having to be very creative, we will call it the PostgreSQL Assistant.
Why is that better than asking your questions on ChatGPT, Stack Overflow or Reddit? We will give short answers:
- ChatGPT: It can hallucinate and give you wrong answers. Or the answer applies to an older version of PostgresSQL.
- Reddit: You have to wait for an answer, and you might not get one - or it can be wrong.
- Stack Overflow: Same as above, furthermore the community is shrinking and the quality of answers is decreasing.

Key metrics for Stack Overflow are in decline.
PostgreSQL Assistant is like having a PostgreSQL expert at your fingertips because all answers come from the official PostgreSQL documentation. Without further ado, let's get down to it.
Step 1: Create a collection
Login to Needle and create an empty collection named PostgreSQL Assistant. Click on the collection to open it and go to Files tab. Click on the Add Files button use the URL adder and enter the value: https://www.postgresql.org/files/documentation/pdf/16/postgresql-16-A4.pdf

Adding file to Needle collection via web interface.
You can, of course, do this via the Needle API as well. That can come in handy in case you want to integrate Needle into your automations. See the code sample below:
from needle.v1 import NeedleClient
from needle.v1.models import FileToAdd
ndl = NeedleClient()
collection = ndl.collections.create(name="PostgreSQL Assistant")
ndl.collections.files.add(
collection_id=collection.id,
files=[
FileToAdd(
url="https://www.postgresql.org/files/documentation/pdf/16/postgresql-16-A4.pdf",
name="PostgreSQL 16 Documentation",
)
],
)