Qdrant

Code

1from kern.agent import Agent
2from kern.db.postgres import PostgresDb
3from kern.knowledge.knowledge import Knowledge
4from kern.vectordb.qdrant import Qdrant
5
6COLLECTION_NAME = "thai-recipes"
7
8vector_db = Qdrant(collection=COLLECTION_NAME, url="http://localhost:6333")
9
10contents_db = PostgresDb(
11 db_url="postgresql+psycopg://ai:ai@localhost:5532/ai",
12 knowledge_table="knowledge_contents",
13)
14
15knowledge = Knowledge(
16 name="My Qdrant Vector Knowledge Base",
17 description="This is a knowledge base that uses a Qdrant Vector DB",
18 vector_db=vector_db,
19 contents_db=contents_db,
20)
21
22knowledge.insert(
23 name="Recipes",
24 url="https://kern-public.s3.amazonaws.com/recipes/ThaiRecipes.pdf",
25 metadata={"doc_type": "recipe_book"},
26)
27
28agent = Agent(knowledge=knowledge)
29agent.print_response("List down the ingredients to make Massaman Gai", markdown=True)
30
31vector_db.delete_by_name("Recipes")
32
33vector_db.delete_by_metadata({"doc_type": "recipe_book"})

Usage

Set up your virtual environment

1uv venv --python 3.12
2source .venv/bin/activate
1uv venv --python 3.12
2.venv\Scripts\activate

Install dependencies

1uv pip install -U qdrant-client pypdf openai kern-ai

Run Qdrant

1docker run -d --name qdrant -p 6333:6333 qdrant/qdrant:latest

Run Agent

1python cookbook/08_knowledge/vector_db/qdrant_db/qdrant_db.py