Skip to content

Instantly share code, notes, and snippets.

@wilyJ80
Created July 30, 2026 20:37
Show Gist options
  • Select an option

  • Save wilyJ80/ac0ddfc32c54fa341b12fca73d57bd69 to your computer and use it in GitHub Desktop.

Select an option

Save wilyJ80/ac0ddfc32c54fa341b12fca73d57bd69 to your computer and use it in GitHub Desktop.
rerank test
import httpx
MAX_TOKENS = 2048
truncated_snippets = []
print('[INFO] Reading file...')
snippets = []
with open('./pacmanlog.txt', 'r') as f:
snippets = f.readlines()
print('[INFO] Chunking content...')
client = httpx.Client(
base_url="https://url.com",
headers={
"Authorization": "Bearer mysecretkey",
},
timeout=120
)
try:
response = client.get("/v1/models")
response = response.json()
except Exception:
print('[ERROR] Could not reach server.')
exit(1)
tok_count = 0
for idx, doc in enumerate(snippets, start=1):
print(f'[INFO] Tokenizing/detokenizing line {idx}/{len(snippets)}')
tok_response = client.post(
'/tokenize',
json={"content": doc}
)
tokens = tok_response.json()['tokens']
tok_count += len(tokens)
print(tok_count)
if tok_count > MAX_TOKENS:
break
else:
truncated_snippets.append(doc)
json = None
print('[INFO] Reranking...')
try:
response = client.post(
"/rerank",
json={
"model": "qwen3-reranker-0.6b-q8_0.gguf",
"query": "When did I mess with nvim?",
"documents": truncated_snippets,
"top_n": 2,
},
)
json = response.json()
except Exception as e:
print(f"[ERROR] {e}")
exit(1)
for result in json["results"]:
print(truncated_snippets[result['index']])
@wilyJ80

wilyJ80 commented Aug 3, 2026

Copy link
Copy Markdown
Author

embeddings: llama-server -m embeddinggemma-300M-Q8_0.gguf --embeddings --pooling mean -c 2048 -b 2048 -ub 2048 -np 1

@wilyJ80

wilyJ80 commented Aug 3, 2026

Copy link
Copy Markdown
Author

reranking: llama-server -m ./qwen3-reranker-0.6b-q8_0.gguf --reranking -c 2048 -b 2048 -ub 2048 --pooling rank

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment