riptano / antora-ui-docs

Mozilla Public License 2.0
1 stars 0 forks source link

DOC-3881: Revert to Highlight.js, fix admonition issues #112

Closed eric-schneider closed 8 months ago

eric-schneider commented 8 months ago

To test highlight.js, check for code callout rendering:

[source,python]
----
import os
os.environ["ASTRA_DB_APPLICATION_TOKEN"] = "<Astra DB API endpoint>" // <.>
os.environ["ASTRA_DB_API_ENDPOINT"] = "<AstraCS:...>" // <.>
----
<.> Replace `<Astra DB API endpoint>` with your *API endpoint*.
<.> Replace `<AstraCS:...>` with your *Application token*.

To test admonitions:

[IMPORTANT]
======
Data is not directly protected by TDE when you access the data using the following utilities.

[cols="1,3"]
|===
| Utility | Reason utility is not encrypted

| nodetool
| Uses only JMX, so data is not accessed.

| sstableloader
| Operates directly on the SSTables.

| sstablescrub
| Operates directly on the SSTables.

| sstableutil
| Operates directly on the SSTables.

| sstableverify
| Operates directly on the SSTables.
|===

[NOTE]
====
A note.
====
======
eric-schneider commented 8 months ago

Stress-tested things with the following syntax, and things look good!

= {astra_db} FAQs
:slug: datastax-astra-faq

Frequently asked questions about {company} {astra_db}.

[IMPORTANT]
======
Data is not directly protected by TDE when you access the data using the following utilities.

[cols="1,3"]
|===
| Utility | Reason utility is not encrypted

| nodetool
| Uses only JMX, so data is not accessed.

| sstableloader
| Operates directly on the SSTables.

| sstablescrub
| Operates directly on the SSTables.

| sstableutil
| Operates directly on the SSTables.

| sstableverify
| Operates directly on the SSTables.
|===

[NOTE]
====
A note.
====
======

[NOTE]
======
A note.

[NOTE]
====
Another admonition.
====
======

[NOTE]
======
A note.

[IMPORTANT]
====
Another admonition.
====
======

[NOTE]
======
A note.

[TIP]
====
Another admonition.
====
======

[NOTE]
======
A note.

[WARNING]
====
Another admonition.
====
======

[NOTE]
======
A note.

[CAUTION]
====
Another admonition.
====
======

[tabs]
======
Python::
+
.quickstart.py
[source,python]
----
# tag::init[]
import os

from astrapy.db import AstraDB

# Initialize the client
db = AstraDB(
    token=os.environ["ASTRA_DB_APPLICATION_TOKEN"],
    api_endpoint=os.environ["ASTRA_DB_API_ENDPOINT"],
)
# end::init[]

# tag::collection[]
# Create a collection
collection = db.create_collection("vector_test", dimension=5, metric="cosine")
# end::collection[]

# tag::data[]
# Insert documents into the collection
documents = [
    {
        "_id": "1",
        "text": "ChatGPT integrated sneakers that talk to you",
        "$vector": [0.1, 0.15, 0.3, 0.12, 0.05],
    },
    {
        "_id": "2",
        "text": "An AI quilt to help you sleep forever",
        "$vector": [0.45, 0.09, 0.01, 0.2, 0.11],
    },
    {
        "_id": "3",
        "text": "A deep learning display that controls your mood",
        "$vector": [0.1, 0.05, 0.08, 0.3, 0.6],
    },
]
res = collection.insert_many(documents)
# end::data[]

# tag::search[]
# Perform a similarity search
query = [0.15, 0.1, 0.1, 0.35, 0.55]
results = collection.vector_find(query, limit=2, fields={"text", "$vector"})

for document in results:
    print(document)
# end::search[]

# tag::delete[]
# Delete the collection
db.delete_collection(collection_name="vector_test")
# end::delete[]
----
+
[NOTE]
====
Don't name the file `astrapy.py` to avoid a namespace collision.
====

TypeScript::
+
.quickstart.ts
[source,typescript]
----
// tag::init[]
import { AstraDB } from "@datastax/astra-db-ts";

async function main() {

  const { ASTRA_DB_APPLICATION_TOKEN, ASTRA_DB_API_ENDPOINT } = process.env;

  // Initialize the client
  const db = new AstraDB(ASTRA_DB_APPLICATION_TOKEN, ASTRA_DB_API_ENDPOINT);
// end::init[]

// tag::collection[]
  // Create a collection
  await db.createCollection(
    "vector_test",
    {
      "vector": {
        "dimension": 5,
        "metric": "cosine"
      }
    }
  );
  const collection = await db.collection("vector_test");
// end::collection[]

// tag::data[]
  // Insert documents into the collection
  const documents = [
      {
          "_id": "1",
          "text": "ChatGPT integrated sneakers that talk to you",
          "$vector": [0.1, 0.15, 0.3, 0.12, 0.05],
      },
      {
          "_id": "2",
          "text": "An AI quilt to help you sleep forever",
          "$vector": [0.45, 0.09, 0.01, 0.2, 0.11],
      },
      {
          "_id": "3",
          "text": "A deep learning display that controls your mood",
          "$vector": [0.1, 0.05, 0.08, 0.3, 0.6],
      }
  ];
  const results = await collection.insertMany(documents);
// end::data[]

// tag::search[]
  // Define the search options
  const options = {
      sort: {
          "$vector": [0.15, 0.1, 0.1, 0.35, 0.55],
      },
      limit: 5
  };

  // Perform a similarity search
  collection.find({}, options).toArray().then(docs => {
      docs.forEach(doc => console.log(doc));
  });
// end::search[]

// tag::delete[]
  // Delete the collection
  db.dropCollection("vector_test").then(response => {
    console.log(response);
  });
// end::delete[]

// tag::end[]
}

main().catch(console.error);
// end::end[]
----

Java::
+
.src/main/java/com/example/Quickstart.java
[source,java]
----
// tag::init[]
package com.example;

import com.dtsx.astra.sdk.AstraDB;
import com.dtsx.astra.sdk.AstraDBCollection;
import io.stargate.sdk.data.domain.JsonDocument;
import io.stargate.sdk.data.domain.JsonDocumentResult;
import io.stargate.sdk.data.domain.SimilarityMetric;
import io.stargate.sdk.data.domain.CollectionDefinition;
import java.util.List;
import java.util.stream.Stream;

public class Quickstart {

  public static void main(String[] args) {
    // Loading Arguments
    String astraToken = System.getenv("ASTRA_DB_APPLICATION_TOKEN");
    String astraApiEndpoint = System.getenv("ASTRA_DB_API_ENDPOINT");

    // Initialize the client
    AstraDB db = new AstraDB(astraToken, astraApiEndpoint);
    System.out.println("Connected to AstraDB");
// end::init[]

// tag::collection[]
    // Create a collection
    CollectionDefinition colDefinition = CollectionDefinition.builder()
        .name("vector_test")
        .vector(5, SimilarityMetric.cosine)
        .build();
    db.createCollection(colDefinition);
    AstraDBCollection collection = db.collection("vector_test");
// end::collection[]

// tag::data[]
    // Insert documents into the collection
    collection.insertMany(List.of(
        new JsonDocument()
            .id("1")
            .put("text", "ChatGPT integrated sneakers that talk to you")
            .vector(new float[]{0.1f, 0.15f, 0.3f, 0.12f, 0.05f}),
        new JsonDocument()
            .id("2")
            .put("text", "An AI quilt to help you sleep forever")
            .vector(new float[]{0.45f, 0.09f, 0.01f, 0.2f, 0.11f}),
        new JsonDocument()
            .id("3")
            .put("text", "A deep learning display that controls your mood")
            .vector(new float[]{0.1f, 0.05f, 0.08f, 0.3f, 0.6f})
        ));
// end::data[]

// tag::search[]
    // Perform a similarity search
    Stream<JsonDocumentResult> resultsSet = collection.findVector(
        new float[]{0.15f, 0.1f, 0.1f, 0.35f, 0.55f},
        10
    );
    resultsSet.forEach(System.out::println);
// end::search[]

// tag::delete[]
    // Delete the collection
    db.deleteCollection("vector_test");
// end::delete[]

// tag::end[]
  }
}
// end::end[]
----
======

Ignore the streaking green coming off the NOTE (artifact of screenshot app).

image