Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 67 additions & 7 deletions docs/semantic-search.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# /// script
# requires-python = ">=3.10"
# dependencies = [
# "datasets",
# "datasets==3.5.1",
# "marimo>=0.23.6",
# "pinecone==9.0.1",
# ]
Expand Down Expand Up @@ -53,17 +53,77 @@ def _(mo):

### Pinecone API Key

Set your `PINECONE_API_KEY` environment variable before running this notebook.
You can get a free key at [app.pinecone.io](https://app.pinecone.io).
You'll need a free Pinecone API key to run this notebook. Get one at
[app.pinecone.io](https://app.pinecone.io).

**Running locally?** Set `PINECONE_API_KEY` in your environment or in a `.env`
file — marimo reads `.env` files automatically on startup. The cell below will
detect the key and confirm it's loaded.

**Running in molab?** Enter your key directly in the input field below.
""")
return


@app.cell
def _(Pinecone, os):
# Initialize client
api_key = os.environ.get("PINECONE_API_KEY")
@app.cell(hide_code=True)
def _(mo, os):
env_key = os.environ.get("PINECONE_API_KEY", "")

api_key_input = mo.ui.text(
kind="password",
placeholder="pcsk_...",
label="Pinecone API Key",
value=env_key,
full_width=True,
)

(
mo.callout(mo.md("API key loaded from environment."), kind="success")
if env_key
else mo.vstack(
[
mo.callout(
mo.md(
"Enter your Pinecone API key. Get a free key at [app.pinecone.io](https://app.pinecone.io)."
),
kind="info",
),
api_key_input,
]
)
)
return (api_key_input,)


@app.cell(hide_code=True)
def _(api_key_input, mo):
api_key = api_key_input.value
mo.stop(
not api_key,
mo.callout(
mo.md("**API key required.** Enter your key above to continue."),
kind="danger",
),
)
return (api_key,)


@app.cell(hide_code=True)
def _(mo):
mo.md(r"""
### Instantiating the Client

With the API key in hand, we can create a `Pinecone` client. This is the entry point for all
control-plane operations — creating and managing indexes, listing namespaces, and so on.

The `source_tag` parameter is used internally by Pinecone to attribute API usage from example
notebooks. You would not include this in your own applications.
""")
return


@app.cell(hide_code=True)
def _(Pinecone, api_key):
pc = Pinecone(
api_key=api_key,
source_tag="pinecone_examples:docs:semantic_search",
Expand Down
Loading