Files
wehub-resource-sync 2cab53bc94
Test Vector Database Adaptors / Test MCP Vector DB Tools (push) Has been cancelled
Tests / Code Quality (Ruff & Mypy) (push) Has been cancelled
Tests / Fast Unit Tests (parallel) (macos-latest, 3.11) (push) Has been cancelled
Tests / Fast Unit Tests (parallel) (macos-latest, 3.12) (push) Has been cancelled
Tests / Tests (push) Has been cancelled
Docker Publish / Build and Push Docker Images (map[description:Skill Seekers CLI - Convert documentation to AI skills dockerfile:Dockerfile name:skill-seekers]) (push) Has been cancelled
Docker Publish / Build and Push Docker Images (map[description:Skill Seekers MCP Server - 25 tools for AI assistants dockerfile:Dockerfile.mcp name:skill-seekers-mcp]) (push) Has been cancelled
Docker Publish / Test Docker Images (push) Has been cancelled
Tests / Fast Unit Tests (parallel) (ubuntu-latest, 3.10) (push) Has been cancelled
Tests / Fast Unit Tests (parallel) (ubuntu-latest, 3.11) (push) Has been cancelled
Tests / Fast Unit Tests (parallel) (ubuntu-latest, 3.12) (push) Has been cancelled
Tests / Serial / Integration / E2E Tests (push) Has been cancelled
Tests / MCP Server Tests (push) Has been cancelled
Test Vector Database Adaptors / Test chroma Adaptor (push) Has been cancelled
Test Vector Database Adaptors / Test faiss Adaptor (push) Has been cancelled
Test Vector Database Adaptors / Test qdrant Adaptor (push) Has been cancelled
Test Vector Database Adaptors / Test weaviate Adaptor (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 12:46:28 +08:00

73 lines
2.0 KiB
Python

#!/usr/bin/env python3
"""Query FAISS index"""
import json, sys, os
import numpy as np
try:
import faiss
from openai import OpenAI
from rich.console import Console
from rich.table import Table
except ImportError:
print("❌ Run: pip install -r requirements.txt")
sys.exit(1)
console = Console()
# Load index and metadata
console.print("📥 Loading FAISS index...")
index = faiss.read_index("flask.index")
with open("flask_metadata.json") as f:
data = json.load(f)
console.print(f"✅ Loaded {index.ntotal} vectors")
# Initialize OpenAI
client = OpenAI(api_key=os.getenv("OPENAI_API_KEY"))
def search(query_text: str, k: int = 5):
"""Search FAISS index"""
console.print(f"\n[yellow]Query:[/yellow] {query_text}")
# Generate query embedding
response = client.embeddings.create(
model="text-embedding-ada-002",
input=query_text
)
query_vector = np.array([response.data[0].embedding]).astype('float32')
# Search
distances, indices = index.search(query_vector, k)
# Display results
table = Table(show_header=True, header_style="bold magenta")
table.add_column("#", width=3)
table.add_column("Distance", width=10)
table.add_column("Category", width=12)
table.add_column("Content Preview")
for i, (dist, idx) in enumerate(zip(distances[0], indices[0]), 1):
doc = data["documents"][idx]
meta = data["metadatas"][idx]
preview = doc[:80] + "..." if len(doc) > 80 else doc
table.add_row(
str(i),
f"{dist:.2f}",
meta.get("category", "N/A"),
preview
)
console.print(table)
console.print("[dim]💡 Distance: Lower = more similar[/dim]")
# Example queries
console.print("[bold green]FAISS Query Examples[/bold green]\n")
search("How do I create a Flask route?", k=3)
search("database models and ORM", k=3)
search("authentication and security", k=3)
console.print("\n✅ All examples completed!")