jaothan commited on
Commit
f766ad9
·
verified ·
1 Parent(s): a838997

Upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +74 -0
  2. docker-compose.yaml +21 -0
app.py ADDED
@@ -0,0 +1,74 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from pinecone.grpc import PineconeGRPC, GRPCClientConfig
2
+ from pinecone import ServerlessSpec
3
+ import time
4
+
5
+ # Initialize a client.
6
+ # API key is required, but the value does not matter.
7
+ # Host and port of the Pinecone Local instance
8
+ # is required when starting without indexes.
9
+ pc = PineconeGRPC(
10
+ api_key="pclocal",
11
+ host="http://localhost:5080"
12
+ )
13
+
14
+ # Create an index
15
+ index_name = "example-index"
16
+
17
+ if not pc.has_index(index_name):
18
+ pc.create_index(
19
+ name=index_name,
20
+ dimension=2,
21
+ metric="cosine",
22
+ spec=ServerlessSpec(
23
+ cloud="aws",
24
+ region="us-east-1",
25
+ )
26
+ )
27
+
28
+ # Wait for the index to be ready
29
+ while not pc.describe_index(index_name).status['ready']:
30
+ time.sleep(1)
31
+
32
+ # Target the index, disabling tls
33
+ index_host = pc.describe_index(index_name).host
34
+ index = pc.Index(host=index_host, grpc_config=GRPCClientConfig(secure=False))
35
+
36
+ # Upsert records into the index
37
+ index.upsert(
38
+ vectors=[
39
+ {
40
+ "id": "vec1",
41
+ "values": [1.0, -2.5],
42
+ "metadata": {"genre": "drama"}
43
+ },
44
+ {
45
+ "id": "vec2",
46
+ "values": [3.0, -2.0],
47
+ "metadata": {"genre": "documentary"}
48
+ },
49
+ {
50
+ "id": "vec3",
51
+ "values": [0.5, -1.5],
52
+ "metadata": {"genre": "documentary"}
53
+ }
54
+ ],
55
+ namespace="example-namespace"
56
+ )
57
+
58
+ # Check the number of records in the index
59
+ print("Index stats:\n", index.describe_index_stats())
60
+
61
+ # Query the index with a metadata filter
62
+ response = index.query(
63
+ vector=[3.0, -2.0],
64
+ filter={"genre": {"$eq": "documentary"}},
65
+ top_k=1,
66
+ include_values=True,
67
+ include_metadata=True,
68
+ namespace='example-namespace'
69
+ )
70
+
71
+ print("\nQuery response:\n", response)
72
+
73
+ # Delete the index
74
+ pc.delete_index(index_name)
docker-compose.yaml ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ services:
2
+ index1:
3
+ image: ghcr.io/pinecone-io/pinecone-index:latest
4
+ environment:
5
+ PORT: 5080
6
+ INDEX_TYPE: serverless
7
+ DIMENSION: 2
8
+ METRIC: cosine
9
+ ports:
10
+ - "5081:5081"
11
+ platform: linux/amd64
12
+ index2:
13
+ image: ghcr.io/pinecone-io/pinecone-index:latest
14
+ environment:
15
+ PORT: 5081
16
+ INDEX_TYPE: pod
17
+ DIMENSION: 2
18
+ METRIC: dotproduct
19
+ ports:
20
+ - "5082:5082"
21
+ platform: linux/amd64