MCPcopy Create free account
hub / github.com/Azure-Samples/rag-postgres-openai-python / source_retriever

Function source_retriever

evals/generate_ground_truth.py:46–65  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

44
45
46def source_retriever() -> Generator[str, None, None]:
47 # Connect to the database
48 DBHOST = os.environ["POSTGRES_HOST"]
49 DBUSER = os.environ["POSTGRES_USERNAME"]
50 DBPASS = os.environ["POSTGRES_PASSWORD"]
51 DBNAME = os.environ["POSTGRES_DATABASE"]
52 DATABASE_URI = f"postgresql://{DBUSER}:{DBPASS}@{DBHOST}/{DBNAME}"
53 engine = create_engine(DATABASE_URI, echo=False)
54 with Session(engine) as session:
55 # Fetch all products for a particular type
56 item_types = session.scalars(select(Item.type).distinct())
57 for item_type in item_types:
58 records = list(session.scalars(select(Item).filter(Item.type == item_type).order_by(Item.id)))
59 logger.info(f"Processing database records for type: {item_type}")
60 yield "\n\n".join([f"## Product ID: [{record.id}]\n" + record.to_str_for_rag() for record in records])
61 # Fetch each item individually
62 # records = list(session.scalars(select(Item).order_by(Item.id)))
63 # for record in records:
64 # logger.info(f"Processing database record: {record.name}")
65 # yield f"## Product ID: [{record.id}]\n" + record.to_str_for_rag()
66
67
68def source_to_text(source) -> str:

Callers 1

Calls 1

to_str_for_ragMethod · 0.45

Tested by

no test coverage detected