Skip to content

Commit 8d0eb0d

Browse files
committed
refactor(client): rename get_by_id to get and update tests
* Update method names for consistency and clarity * Refactor tests to use new method names * Improve pagination and filtering examples in usage scripts
1 parent 6531a90 commit 8d0eb0d

File tree

7 files changed

+127
-282
lines changed

7 files changed

+127
-282
lines changed

examples/basic_usage.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def main():
4343
print(f" [{rowid}] {text[:50]}... (distance: {distance:.4f})")
4444

4545
# Get record by ID
46-
record = client.get_by_id(rowids[0])
46+
record = client.get(rowids[0])
4747
if record:
4848
rowid, text, metadata, embedding = record
4949
print(f"\nRecord {rowid}: {text}")

examples/batch_operations.py

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,12 @@ def main():
2626
rowids = client.add(texts=texts, embeddings=embeddings, metadata=metadata)
2727
print(f"Inserted {len(rowids)} products")
2828

29-
# Pagination - list first page
29+
# Pagination using get_all with batch_size
3030
page_size = 10
31-
page_1 = client.list_results(limit=page_size, offset=0, order="asc")
32-
print(f"\nPage 1 ({len(page_1)} items):")
33-
for rowid, text, meta, _ in page_1[:3]:
34-
print(f" [{rowid}] {text} - ${meta['price']}")
35-
36-
# Pagination - list second page
37-
page_2 = client.list_results(limit=page_size, offset=page_size, order="asc")
38-
print(f"\nPage 2 ({len(page_2)} items):")
39-
for rowid, text, meta, _ in page_2[:3]:
31+
print(f"\nFirst {page_size} items:")
32+
for i, (rowid, text, meta, _) in enumerate(client.get_all(batch_size=page_size)):
33+
if i >= 3:
34+
break
4035
print(f" [{rowid}] {text} - ${meta['price']}")
4136

4237
# Batch retrieval

examples/metadata_filtering.py

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22
33
Demonstrates:
44
- Adding records with metadata
5-
- Filtering by metadata
6-
- Filtering by text
5+
- Querying records with get_all
76
- Updating metadata
87
"""
98

@@ -36,17 +35,17 @@ def main():
3635
rowids = client.add(texts=texts, embeddings=embeddings, metadata=metadata)
3736
print(f"Added {len(rowids)} articles")
3837

39-
# Filter by exact metadata match
40-
alice_articles = client.get_by_metadata(
41-
{"category": "programming", "author": "Alice", "year": 2023}
42-
)
43-
print(f"\nAlice's programming articles: {len(alice_articles)}")
44-
for rowid, text, meta, _ in alice_articles:
45-
print(f" [{rowid}] {text} - {meta}")
38+
# Query all articles and filter by author
39+
print("\nAlice's articles:")
40+
for rowid, text, meta, _ in client.get_all():
41+
if meta.get("author") == "Alice":
42+
print(f" [{rowid}] {text} - {meta}")
4643

47-
# Filter by text
48-
python_articles = client.get_by_text("Python for data science")
49-
print(f"\nPython articles: {len(python_articles)}")
44+
# Query all articles and filter by text
45+
print("\nPython-related articles:")
46+
for rowid, text, meta, _ in client.get_all():
47+
if "Python" in text:
48+
print(f" [{rowid}] {text}")
5049

5150
# Update metadata
5251
if rowids:
@@ -59,7 +58,7 @@ def main():
5958
"updated": True,
6059
},
6160
)
62-
updated = client.get_by_id(rowids[0])
61+
updated = client.get(rowids[0])
6362
if updated:
6463
print(f"\nUpdated metadata: {updated[2]}")
6564

examples/real_world_scenario.py

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -81,21 +81,22 @@ def main():
8181

8282
print("Top 3 results:")
8383
for i, (rowid, text, distance) in enumerate(results, 1):
84-
record = client.get_by_id(rowid)
84+
record = client.get(rowid)
8585
if record:
8686
_, _, meta, _ = record
8787
print(f" {i}. [{meta['category']}] {text[:60]}...")
8888
print(
8989
f" Distance: {distance:.4f}, Difficulty: {meta['difficulty']}\n"
9090
)
9191

92-
# Filter by category
93-
print("All AI-related documents:")
94-
ai_docs = client.get_by_metadata(
95-
{"category": "ai", "language": "general", "difficulty": "intermediate"}
96-
)
97-
for rowid, text, meta, _ in ai_docs:
98-
print(f" • {text[:60]}...")
92+
# Filter by category using get_all
93+
print("All AI-related documents (intermediate):")
94+
for rowid, text, meta, _ in client.get_all():
95+
if (
96+
meta.get("category") == "ai"
97+
and meta.get("difficulty") == "intermediate"
98+
):
99+
print(f" • {text[:60]}...")
99100

100101
# Update document
101102
if rowids:
@@ -114,9 +115,12 @@ def main():
114115
print("\nKnowledge base statistics:")
115116
print(f" Total documents: {client.count()}")
116117

117-
# List recent documents
118-
recent = client.list_results(limit=3, offset=0, order="desc")
119-
print(f" Most recent: {len(recent)} documents")
118+
# List first 3 documents
119+
print(" First 3 documents:")
120+
for i, (rowid, text, _, _) in enumerate(client.get_all()):
121+
if i >= 3:
122+
break
123+
print(f" [{rowid}] {text[:50]}...")
120124

121125

122126
if __name__ == "__main__":

0 commit comments

Comments
 (0)