Skip to content

Commit

Permalink
cr
Browse files Browse the repository at this point in the history
  • Loading branch information
EmanuelCampos committed Sep 29, 2023
1 parent 2947338 commit 88fc759
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 16 deletions.
2 changes: 1 addition & 1 deletion llama_hub/library.json
Original file line number Diff line number Diff line change
Expand Up @@ -921,7 +921,7 @@
"author": "zep",
"keywords": ["zep", "retriever", "memory", "storage"]
},
"MacrometaGDNLoader": {
"MacrometaGDNReader": {
"id": "macrometa_gdn",
"author": "Dain Im",
"keywords": [
Expand Down
4 changes: 2 additions & 2 deletions llama_hub/macrometa_gdn/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ To use this loader, you need to pass the URL and API key through the class contr
```python
from llama_index import download_loader

MacrometaGDNLoader = download_loader('MacrometaGDNLoader')
MacrometaGDNReader = download_loader('MacrometaGDNReader')

collections = ['test_collection']
loader = MacrometaGDNLoader(url="https://api-macrometa.io",apikey="test")
loader = MacrometaGDNReader(url="https://api-macrometa.io",apikey="test")
vectors= loader.load_data(collection_list=collections)
```
31 changes: 18 additions & 13 deletions llama_hub/macrometa_gdn/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@
from llama_index.readers.base import BaseReader
from llama_index.readers.schema.base import Document


class MacrometaGDNReader(BaseReader):
"""Macrometa GDN Reader.
Reads vectors from Macrometa GDN
Expand All @@ -21,21 +22,25 @@ def __init__(self, url: str, apikey: str):

def load_data(self, collection_list: List[str]) -> List[Document]:
"""Loads data from the input directory.
Args:
api: Macrometa GDN API key
collection_name: Name of the collection to read from
"""
if collection_list is None:
raise ValueError("Must specify collection name(s)")

results = []
for collection_name in collection_list:
collection = self._load_collection(collection_name)
results.append(Document(text=collection, extra_info={"collection_name": collection_name}))
results.append(
Document(
text=collection, extra_info={"collection_name": collection_name}
)
)
return results

def _load_collection(self, collection_name: str) -> str:
all_documents = []
"""Loads a collection from the database.
Expand All @@ -48,29 +53,29 @@ def _load_collection(self, collection_name: str) -> str:
headers = {
"accept": "application/json",
"content-type": "application/json",
"Authorization": "apikey " + self.apikey
"Authorization": "apikey " + self.apikey,
}

data = {
"batchSize": 1000,
"ttl": 60,
"query": "FOR doc IN " + collection_name + " RETURN doc"
"query": "FOR doc IN " + collection_name + " RETURN doc",
}
response = requests.post(url, headers=headers, data=json.dumps(data))
response_json = response.json()
if response.status_code == 201:
all_documents.extend(response_json.get('result', []))
all_documents.extend(response_json.get("result", []))

while response_json.get('hasMore'):
cursor_id = response_json.get('id')
while response_json.get("hasMore"):
cursor_id = response_json.get("id")

next_url = self.url + "/_fabric/_system/_api/cursor/" + cursor_id

response = requests.put(next_url, headers=headers)

if response.status_code == 200:
response_json = response.json()
all_documents.extend(response_json.get('result', []))
all_documents.extend(response_json.get("result", []))
else:
print(f"Request failed with status code {response.status_code}")
break
Expand All @@ -79,7 +84,7 @@ def _load_collection(self, collection_name: str) -> str:

return str(all_documents)


if __name__ == "__main__":
reader = MacrometaGDNReader("https://api-anurag.eng.macrometa.io", "test")
print(reader.load_data(collection_list=["test"]))

0 comments on commit 88fc759

Please sign in to comment.