-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.html
169 lines (161 loc) · 16.6 KB
/
index.html
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
<!DOCTYPE HTML>
<html lang="en">
<head>
<!-- Generated by javadoc (21) on Tue Jul 09 22:47:20 CEST 2024 -->
<title>Overview (Java Client Library for Data API 1.4.0 API)</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="dc.created" content="2024-07-09">
<meta name="description" content="package index">
<meta name="generator" content="javadoc/PackageIndexWriter">
<link rel="stylesheet" type="text/css" href="stylesheet.css" title="Style">
<link rel="stylesheet" type="text/css" href="script-dir/jquery-ui.min.css" title="Style">
<script type="text/javascript" src="script.js"></script>
<script type="text/javascript" src="script-dir/jquery-3.6.1.min.js"></script>
<script type="text/javascript" src="script-dir/jquery-ui.min.js"></script>
</head>
<body class="package-index-page">
<script type="text/javascript">var pathtoroot = "./";
loadScripts(document, 'script');</script>
<noscript>
<div>JavaScript is disabled on your browser.</div>
</noscript>
<div class="flex-box">
<header role="banner" class="flex-header">
<nav role="navigation">
<!-- ========= START OF TOP NAVBAR ======= -->
<div class="top-nav" id="navbar-top"><button id="navbar-toggle-button" aria-controls="navbar-top" aria-expanded="false" aria-label="Toggle navigation links"><span class="nav-bar-toggle-icon"> </span><span class="nav-bar-toggle-icon"> </span><span class="nav-bar-toggle-icon"> </span></button>
<div class="skip-nav"><a href="#skip-navbar-top" title="Skip navigation links">Skip navigation links</a></div>
<ul id="navbar-top-firstrow" class="nav-list" title="Navigation">
<li class="nav-bar-cell1-rev">Overview</li>
<li>Package</li>
<li>Class</li>
<li>Use</li>
<li><a href="overview-tree.html">Tree</a></li>
<li><a href="deprecated-list.html">Deprecated</a></li>
<li><a href="index-all.html">Index</a></li>
<li><a href="help-doc.html#overview">Help</a></li>
</ul>
</div>
<div class="sub-nav">
<div id="navbar-sub-list"></div>
<div class="nav-list-search"><a href="search.html">SEARCH</a>
<input type="text" id="search-input" disabled placeholder="Search">
<input type="reset" id="reset-button" disabled value="reset">
</div>
</div>
<!-- ========= END OF TOP NAVBAR ========= -->
<span class="skip-nav" id="skip-navbar-top"></span></nav>
</header>
<div class="flex-content">
<main role="main">
<div class="header">
<h1 class="title">Java Client Library for Data API 1.4.0 API</h1>
</div>
<div class="block"><h1 id="overview-heading">Overview</h1>
<p>
This client library provides a simplified way to interact with Data API with DataStax AstraDB or local deployments ( Stargate + Cassandra). </p>
<p>More resources can be found:</p>
<ul>
<li>In <b><a href="https://docs.datastax.com/en/astra/astra-db-vector/clients/usage.html">Datastax Astra Client documentation page</a></b></li>
<li>In the <b> <a href="https://github.com/datastax/astra-db-java">github repository</a></b> with an <code>examples</code> section. </li>
</ul>
<p><img src="https://datastaxdevs.github.io/astra-db-java/overview.png" alt="logicial overview" height="400px"></p>
<h2 id="installation-heading">Installation</h2>
<p>For Maven, add the following dependency to your <code>pom.xml</code>:</p>
<div style="background: #ffffff; font-size:10px;overflow:auto;width:auto;border:solid gray;border-width:.1em .1em .1em .1em;padding:.2em .6em;"><pre style="margin: 0; line-height: 125%"><span style="color: #007700"><dependency></span>
<span style="color: #007700"><groupId></span>com.datastax.astra<span style="color: #007700"></groupId></span>
<span style="color: #007700"><artifactId></span>astra-db-java<span style="color: #007700"></artifactId></span>
<span style="color: #007700"><version></span>1.0.0-SNAPSHOT<span style="color: #007700"></version></span>
<span style="color: #007700"></dependency></span>
</pre></div>
<h2 id="quickstart-heading">QuickStart</h2>
<div style="background: #f8f8f8; font-size:10px;overflow:auto;width:auto;border:solid gray;border-width:.1em .1em .1em .1em;padding:.2em .6em;"><pre style="margin: 0; line-height: 125%">
<span style="color: #008000;">import</span> <span style="color: #0000FF;">com.datastax.astra.client.DataAPIClient</span><span style="color: #666666">;</span>
<span style="color: #008000;">import</span> <span style="color: #0000FF;">com.datastax.astra.client.Collection</span><span style="color: #666666">;</span>
<span style="color: #008000;">import</span> <span style="color: #0000FF;">com.datastax.astra.client.Database</span><span style="color: #666666">;</span>
<span style="color: #008000;">import</span> <span style="color: #0000FF;">com.datastax.astra.client.model.Document</span><span style="color: #666666">;</span>
<span style="color: #008000;">import</span> <span style="color: #0000FF;">com.datastax.astra.client.model.FindIterable</span><span style="color: #666666">;</span>
<span style="color: #008000;">import</span> <span style="color: #0000FF;">java.util.List</span><span style="color: #666666">;</span>
<span style="color: #008000;">import</span> <span style="color: #0000FF;">static</span> com<span style="color: #666666">.</span><span style="color: #7D9029">datastax</span><span style="color: #666666">.</span><span style="color: #7D9029">astra</span><span style="color: #666666">.</span><span style="color: #7D9029">client</span><span style="color: #666666">.</span><span style="color: #7D9029">model</span><span style="color: #666666">.</span><span style="color: #7D9029">Filters</span><span style="color: #666666">.</span><span style="color: #7D9029">eq</span><span style="color: #666666">;</span>
<span style="color: #008000;">import</span> <span style="color: #0000FF;">static</span> com<span style="color: #666666">.</span><span style="color: #7D9029">datastax</span><span style="color: #666666">.</span><span style="color: #7D9029">astra</span><span style="color: #666666">.</span><span style="color: #7D9029">client</span><span style="color: #666666">.</span><span style="color: #7D9029">model</span><span style="color: #666666">.</span><span style="color: #7D9029">SimilarityMetric</span><span style="color: #666666">.</span><span style="color: #7D9029">cosine</span><span style="color: #666666">;</span>
<span style="color: #008000; font-weight: bold">public</span> <span style="color: #008000; font-weight: bold">class</span> <span style="color: #0000FF; font-weight: bold">GettingStarted</span> <span style="color: #666666">{</span>
<span style="color: #008000; font-weight: bold">public</span> <span style="color: #008000; font-weight: bold">static</span> <span style="color: #B00040">void</span> <span style="color: #0000FF">main</span><span style="color: #666666">(</span>String<span style="color: #666666">[]</span> args<span style="color: #666666">)</span> <span style="color: #666666">{</span>
<span style="color: #408080; font-style: italic">// Initializing client with a token</span>
DataAPIClient client <span style="color: #666666">=</span> <span style="color: #008000; font-weight: bold">new</span> DataAPIClient<span style="color: #666666">(</span><span style="color: #BA2121">"my_token"</span><span style="color: #666666">);</span>
<span style="color: #408080; font-style: italic">// Accessing the Database through the HTTP endpoint</span>
Database db <span style="color: #666666">=</span> client<span style="color: #666666">.</span><span style="color: #7D9029">getDatabase</span><span style="color: #666666">(</span><span style="color: #BA2121">"http://db-region.apps.astra.datastax.com"</span><span style="color: #666666">);</span>
<span style="color: #408080; font-style: italic">// Create collection with vector support</span>
Collection<span style="color: #666666"><</span>Document<span style="color: #666666">></span> col <span style="color: #666666">=</span> db<span style="color: #666666">.</span><span style="color: #7D9029">createCollection</span><span style="color: #666666">(</span><span style="color: #BA2121">"demo"</span><span style="color: #666666">,</span> <span style="color: #666666">2,</span> cosine<span style="color: #666666">);</span>
<span style="color: #408080; font-style: italic">// Insert documents with embeddings</span>
col<span style="color: #666666">.</span><span style="color: #7D9029">insertMany</span><span style="color: #666666">(</span>List<span style="color: #666666">.</span><span style="color: #7D9029">of</span><span style="color: #666666">(</span>
<span style="color: #008000; font-weight: bold">new</span> <span style="color: #0000FF">Document</span><span style="color: #666666">(</span><span style="color: #BA2121">"doc1"</span><span style="color: #666666">).</span><span style="color: #7D9029">vector</span><span style="color: #666666">(</span><span style="color: #008000; font-weight: bold">new</span> <span style="color: #B00040">float</span><span style="color: #666666">[]{.1</span>f<span style="color: #666666">,</span> <span style="color: #666666">0.2f}).</span><span style="color: #7D9029">append</span><span style="color: #666666">(</span><span style="color: #BA2121">"key"</span><span style="color: #666666">,</span> <span style="color: #BA2121">"value1"</span><span style="color: #666666">),</span>
<span style="color: #008000; font-weight: bold">new</span> <span style="color: #0000FF">Document</span><span style="color: #666666">().</span><span style="color: #7D9029">id</span><span style="color: #666666">(</span><span style="color: #BA2121">"doc2"</span><span style="color: #666666">).</span><span style="color: #7D9029">vector</span><span style="color: #666666">(</span><span style="color: #008000; font-weight: bold">new</span> <span style="color: #B00040">float</span><span style="color: #666666">[]{.2</span>f<span style="color: #666666">,</span> <span style="color: #666666">0.4f}).</span><span style="color: #7D9029">append</span><span style="color: #666666">(</span><span style="color: #BA2121">"hello"</span><span style="color: #666666">,</span> <span style="color: #BA2121">"world"</span><span style="color: #666666">),</span>
<span style="color: #008000; font-weight: bold">new</span> <span style="color: #0000FF">Document</span><span style="color: #666666">(</span><span style="color: #BA2121">"doc3"</span><span style="color: #666666">).</span><span style="color: #7D9029">vector</span><span style="color: #666666">(</span><span style="color: #008000; font-weight: bold">new</span> <span style="color: #B00040">float</span><span style="color: #666666">[]{.5</span>f<span style="color: #666666">,</span> <span style="color: #666666">0.6f}).</span><span style="color: #7D9029">append</span><span style="color: #666666">(</span><span style="color: #BA2121">"key"</span><span style="color: #666666">,</span> <span style="color: #BA2121">"value1"</span><span style="color: #666666">))</span>
<span style="color: #666666">);</span>
<span style="color: #408080; font-style: italic">// Semantic Search with metadata filtering</span>
FindIterable<span style="color: #666666"><</span>Document<span style="color: #666666">></span> docs <span style="color: #666666">=</span> col<span style="color: #666666">.</span><span style="color: #7D9029">find</span><span style="color: #666666">(</span>
eq<span style="color: #666666">(</span><span style="color: #BA2121">"key"</span><span style="color: #666666">,</span> <span style="color: #BA2121">"value1"</span><span style="color: #666666">),</span> <span style="color: #408080; font-style: italic">// metadata filter</span>
<span style="color: #008000; font-weight: bold">new</span> <span style="color: #B00040">float</span><span style="color: #666666">[]</span> <span style="color: #666666">{.5</span>f<span style="color: #666666">,</span> <span style="color: #666666">.5</span>f<span style="color: #666666">},</span> <span style="color: #408080; font-style: italic">//vector</span>
<span style="color: #666666">10);</span> <span style="color: #408080; font-style: italic">// maxRecord</span>
<span style="color: #408080; font-style: italic">// Iterate over and print your results</span>
<span style="color: #008000; font-weight: bold">for</span> <span style="color: #666666">(</span>Document doc <span style="color: #666666">:</span> docs<span style="color: #666666">)</span> System<span style="color: #666666">.</span><span style="color: #7D9029">out</span><span style="color: #666666">.</span><span style="color: #7D9029">println</span><span style="color: #666666">(</span>doc<span style="color: #666666">);</span>
<span style="color: #666666">}</span>
<span style="color: #666666">}</span>
</pre></div></div>
<div id="all-packages-table">
<div class="caption"><span>Packages</span></div>
<div class="summary-table two-column-summary">
<div class="table-header col-first">Package</div>
<div class="table-header col-last">Description</div>
<div class="col-first even-row-color all-packages-table all-packages-table-tab1"><a href="com/datastax/astra/client/package-summary.html">com.datastax.astra.client</a></div>
<div class="col-last even-row-color all-packages-table all-packages-table-tab1">
<div class="block">Entrypoint and core classes for the client.</div>
</div>
<div class="col-first odd-row-color all-packages-table all-packages-table-tab1"><a href="com/datastax/astra/client/admin/package-summary.html">com.datastax.astra.client.admin</a></div>
<div class="col-last odd-row-color all-packages-table all-packages-table-tab1">
<div class="block">Administration classes to manage Databases and Namespaces.</div>
</div>
<div class="col-first even-row-color all-packages-table all-packages-table-tab1"><a href="com/datastax/astra/client/auth/package-summary.html">com.datastax.astra.client.auth</a></div>
<div class="col-last even-row-color all-packages-table all-packages-table-tab1">
<div class="block">Internal technical classes to authenticate against API endpoint.</div>
</div>
<div class="col-first odd-row-color all-packages-table all-packages-table-tab1"><a href="com/datastax/astra/client/exception/package-summary.html">com.datastax.astra.client.exception</a></div>
<div class="col-last odd-row-color all-packages-table all-packages-table-tab1">
<div class="block">Exceptions specialized checked and unchecked thrown by the client.</div>
</div>
<div class="col-first even-row-color all-packages-table all-packages-table-tab1"><a href="com/datastax/astra/client/model/package-summary.html">com.datastax.astra.client.model</a></div>
<div class="col-last even-row-color all-packages-table all-packages-table-tab1">
<div class="block">Domain model classes with <code>Requests</code>, <code>Results</code>, <code>Options</code> and <code>Iterables</code>.</div>
</div>
<div class="col-first odd-row-color all-packages-table all-packages-table-tab1"><a href="com/datastax/astra/internal/package-summary.html">com.datastax.astra.internal</a></div>
<div class="col-last odd-row-color all-packages-table all-packages-table-tab1">
<div class="block">Internal technical classes</div>
</div>
<div class="col-first even-row-color all-packages-table all-packages-table-tab1"><a href="com/datastax/astra/internal/api/package-summary.html">com.datastax.astra.internal.api</a></div>
<div class="col-last even-row-color all-packages-table all-packages-table-tab1">
<div class="block">Internal technical classes to marshall API responses</div>
</div>
<div class="col-first odd-row-color all-packages-table all-packages-table-tab1"><a href="com/datastax/astra/internal/command/package-summary.html">com.datastax.astra.internal.command</a></div>
<div class="col-last odd-row-color all-packages-table all-packages-table-tab1">
<div class="block">Internal technical classes to run commands against the API.</div>
</div>
<div class="col-first even-row-color all-packages-table all-packages-table-tab1"><a href="com/datastax/astra/internal/http/package-summary.html">com.datastax.astra.internal.http</a></div>
<div class="col-last even-row-color all-packages-table all-packages-table-tab1">
<div class="block">Internal technical classes to execute HTTP requests.</div>
</div>
<div class="col-first odd-row-color all-packages-table all-packages-table-tab1"><a href="com/datastax/astra/internal/utils/package-summary.html">com.datastax.astra.internal.utils</a></div>
<div class="col-last odd-row-color all-packages-table all-packages-table-tab1">
<div class="block">Internal technical classes for low-level utilities</div>
</div>
</div>
</div>
</main>
<footer role="contentinfo">
<hr>
<p class="legal-copy"><small>Copyright © 2024 <a href="https://www.datastax.com">DataStax</a>. All rights reserved.</small></p>
</footer>
</div>
</div>
</body>
</html>