Welcome to the YRAL IcPump Search Service! This guide will help you understand our codebase and get started with development.
This service provides semantic search capabilities over token metadata using Google's BigQuery, Vertex AI, and PaLM APIs. It combines vector embeddings with natural language processing to deliver intelligent search results.
- Python 3.11+
- FastAPI
- Google Cloud Platform
- BigQuery
- Vertex AI
- GeminiAPI
- Docker
- Fly.io for deployment
- Clone the repository
- Create a virtual environment:
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
- Install dependencies:
pip install -r requirements.txt
- Set up environment variables:
export SERVICE_CRED='your_service_account_json'
export GOOGLE_GENAI_API_KEY='your_gemini_api_key'
- Type Hints: Always use type hints for function parameters and return values
def process_query(self, user_query: str, table_name: str = "") -> tuple[pd.DataFrame, str, str]:
- Documentation: Use docstrings for classes and functions
def semantic_search_bq(query_text: str, bq_client: Optional[bigquery.Client] = None) -> pd.DataFrame:
"""
Performs semantic search on BigQuery table.
Args:
query_text: The search query
bq_client: BigQuery client instance
Returns:
DataFrame with search results
"""
- Error Handling: Use try-except blocks for external API calls and file operations
try:
response = self.model.generate_content(contents)
except Exception as e:
logger.error(f"Error generating content: {e}")
raise
- Configuration: Keep configuration in separate files/environment variables
base_table = os.getenv('BASE_TABLE', 'default_table_name')
- All commits to
main
branch trigger automatic deployment via GitHub Actions - Tests must pass before deployment
- Deployment is handled by Fly.io
- Monitor logs post-deployment
Create a simple endpoint that:
- Accepts a user query
- Retrieves some token data from BigQuery
- Uses the LLM to generate a response
- Create a new file
hello_world.py
:
from fastapi import FastAPI
from google.cloud import bigquery
import google.generativeai as genai
import os
import json
from google.oauth2 import service_account
app = FastAPI()
# Initialize credentials
service_cred = os.environ['SERVICE_CRED']
service_acc_creds = json.loads(service_cred, strict=False)
genai.configure(api_key=os.environ['GOOGLE_GENAI_API_KEY'])
credentials = service_account.Credentials.from_service_account_info(service_acc_creds)
bq_client = bigquery.Client(credentials=credentials)
@app.get("/hello")
async def hello_world(query: str):
# 1. Get some sample token data
token_query = """
SELECT token_name, description, created_at
FROM `hot-or-not-feed-intelligence.icpumpfun.token_metadata_v1`
LIMIT 5
"""
df = bq_client.query(token_query).to_dataframe()
# 2. Create LLM model
model = genai.GenerativeModel('gemini-1.0-pro')
# 3. Generate response
prompt = f"""
User Query: {query}
Available Token Data:
{df.to_string()}
Please provide a friendly response about these tokens based on the user's query.
"""
response = model.generate_content(prompt)
return {
"query": query,
"tokens": df.to_dict('records'),
"llm_response": response.text
}
- Run the server:
uvicorn hello_world:app --reload
- Test the endpoint:
curl "http://localhost:8000/hello?query=Tell%20me%20about%20these%20tokens"
{
"query": "Tell me about these tokens",
"tokens": [...],
"llm_response": "Here are some interesting tokens..."
}
- Add error handling
- Implement semantic search
- Add rate limiting
- Implement caching
- Add authentication
- Check the existing code in
search_agent_bq.py
for examples - Review our test cases in
test_case_results.txt
- Reach out to the team on Slack