Back to prompt library
Integrating Pinecone for Factual Verification
Linked challenge: Orchestrate Scientific Integrity Agent Crew
Prompt source
implementation22 lines6 sectionsNo variables1 code block
Create a Python tool that allows the 'Factual Verifier' agent to query a Pinecone vector database. Assume the database is pre-populated with embeddings of scientific articles/facts. The tool should take a query string (a claim from the text) and return relevant supporting or contradicting documents. Provide the tool definition and how to integrate it with the `Factual Verifier` agent.
```python
from crewai_tools import BaseTool
from pinecone import Pinecone, ServerlessSpec
# from your_embedding_model_library import get_embedding # e.g., from an API or a local Mistral Saba model
# Initialize Pinecone (replace with your actual API key and environment)
# pc = Pinecone(api_key="YOUR_PINECONE_API_KEY", environment="YOUR_PINECONE_ENVIRONMENT")
# index = pc.Index("scientific-facts") # Assume an index exists
class PineconeFactCheckerTool(BaseTool):
name: str = "Pinecone Fact Checker"
description: str = "Searches a Pinecone vector database for scientific facts to verify claims."
def _run(self, query: str) -> str:
# query_embedding = get_embedding(query) # Replace with actual embedding call
query_embedding = [0.1] * 768 # Placeholder
# Example Pinecone search
# results = index.query(vector=query_embedding, top_k=3, include_metadata=True)
# formatted_results = [f"Fact: {match.metadata['text']} (Score: {match.score:.2f})" for match in results.matches]
# return "\n".join(formatted_results) if formatted_results else "No relevant facts found."
return f"Simulated Pinecone search for '{query}' returned: Fact X and Fact Y."
# Add the tool to the Factual Verifier agent
# factual_verifier.tools.append(PineconeFactCheckerTool())
```