-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathretriever_testing.py
55 lines (43 loc) · 1.3 KB
/
retriever_testing.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
from dotenv import load_dotenv
import os
import openai
from supabase import create_client
import requests
load_dotenv()
openai_api_key = os.getenv("OPENAI_KEY", "")
supabase_url = os.getenv("SUPABASE_URL", "")
supabase_anon_key = os.getenv("SUPABASE_SERVICE_KEY", "")
supabase_client = create_client(supabase_url, supabase_anon_key)
openai.api_key = openai_api_key
def fetch_documents(input_query):
# Generate a one-time embedding for the query
embedding_response = openai.Embedding.create(
model="text-embedding-ada-002",
input=input_query,
encoding_format="float",
)
embedding = embedding_response['data'][0]['embedding']
# this doesn't work:
#
documents = supabase_client.rpc(
'match_documents',
{
"match_count": 3,
"match_threshold": 0.7,
"query_embedding": embedding,
})
# this works:
#
# documents = requests.post(supabase_url + "/rest/v1/rpc/match_documents", json={
# "match_count": 3,
# "match_threshold": 0.7,
# "query_embedding": embedding
# }, headers={
# "apikey": supabase_anon_key
# })
# documents = documents.json()
return documents
# Example usage
input_query = "Hello"
documents = fetch_documents(input_query)
print(documents)