Create a function to insert documents into Qdrant with tracing:
Copy
Ask AI
@trace()def insert_documents(docs): """Insert documents into Qdrant collection.""" points = [] for idx, doc in enumerate(docs): vector = embed_text(doc) points.append(PointStruct( id=idx + 1, vector=vector, payload={"text": doc} )) client.upsert( collection_name=collection_name, points=points ) return len(points)# Sample documentsdocuments = [ "Qdrant is a vector database optimized for storing and searching high-dimensional vectors.", "HoneyHive provides observability for AI applications, including RAG pipelines.", "Retrieval-Augmented Generation (RAG) combines retrieval systems with generative models.", "Vector databases like Qdrant are essential for efficient similarity search in RAG systems.", "OpenAI's embedding models convert text into high-dimensional vectors for semantic search."]# Insert documentsnum_inserted = insert_documents(documents)
Create a function to generate a response using OpenAI with tracing:
Copy
Ask AI
@trace()def answer_query(query: str, relevant_docs: list) -> str: """Generate an answer for a query using retrieved documents.""" if not relevant_docs: return "Could not retrieve relevant documents to answer the query." # Format context from retrieved documents context_parts = [] for i, doc in enumerate(relevant_docs): context_parts.append(f"Document {i+1} (ID: {doc['id']}, Score: {doc['score']:.4f}):\n{doc['text']}") context = "\n\n".join(context_parts) # Create prompt prompt = f"""Answer the question based ONLY on the following context:Context:{context}Question: {query}Answer:""" # Generate answer completion = openai_client.chat.completions.create( model="gpt-4o-mini", messages=[ {"role": "system", "content": "You are a helpful assistant that answers questions based strictly on the provided context. If the answer is not in the context, say so clearly."}, {"role": "user", "content": prompt} ], temperature=0.2 ) return completion.choices[0].message.content.strip()
# Test querytest_query = "What is Qdrant used for?"result = rag_pipeline(test_query)print(f"Query: {result['query']}")print(f"Answer: {result['answer']}")print("\nRetrieved Documents:")for i, doc in enumerate(result['retrieved_documents']): print(f"Document {i+1} (ID: {doc['id']}, Score: {doc['score']:.4f}): {doc['text']}")
After running your RAG pipeline with Qdrant, you can view the traces in the HoneyHive UI:
Navigate to your project in the HoneyHive dashboard
Click on the “Traces” tab to see all the traces from your RAG pipeline
Click on a specific trace to see detailed information about each step in the pipeline
Analyze the performance of your vector operations, embeddings, and retrieval processes
With HoneyHive, you can easily monitor and optimize your Qdrant-powered RAG pipeline, ensuring that it delivers the best possible results for your users.Visit the Qdrant documentation and the HoneyHive documentation.