from raghilda.store import OpenAIStore
# Create a new store
store = OpenAIStore.create(name="my-store")
# Or connect to an existing store
store = OpenAIStore.connect(store_id="vs_abc123")
# Insert documents
from raghilda.document import MarkdownDocument
doc = MarkdownDocument(content="# Hello\nWorld", origin="example.md")
store.upsert(doc)
# Retrieve similar chunks
chunks = store.retrieve("greeting", top_k=5)store.OpenAIStore
A vector store backed by OpenAI’s Vector Store API.
Usage
store.OpenAIStore()OpenAIStore uses OpenAI’s hosted vector storage service for document storage and retrieval. Documents are uploaded as files and automatically chunked and embedded by OpenAI.
Examples
Methods
| Name | Description |
|---|---|
| connect() | Connect to an existing OpenAI vector store. |
| create() | Create a new OpenAI vector store. |
| retrieve() | Retrieve the most similar chunks to the given text. |
connect()
Connect to an existing OpenAI vector store.
Usage
connect(store_id, base_url="https://api.openai.com/v1", api_key=None)Parameters
store_id: str-
The ID of the vector store to connect to (e.g., “vs_abc123”).
base_url: str = "https://api.openai.com/v1"-
Base URL for the OpenAI API.
api_key: Optional[str] = None- OpenAI API key. If None, uses the OPENAI_API_KEY environment variable.
Returns
OpenAIStore- A connected store instance.
create()
Create a new OpenAI vector store.
Usage
create(
base_url="https://api.openai.com/v1",
api_key=None,
*,
attributes=None,
metadata=None,
**kwargs
)Parameters
base_url: str = "https://api.openai.com/v1"-
Base URL for the OpenAI API.
api_key: Optional[str] = None-
OpenAI API key. If None, uses the OPENAI_API_KEY environment variable.
attributes: Optional[AttributesSchemaSpec] = None-
Optional schema for user-defined attribute columns. Attribute names use identifier-style syntax. OpenAIStore filters only support declared attributes.
metadata: Optional[Mapping[str, str]] = None-
Additional metadata to attach to the OpenAI vector store resource.
**kwargs- Additional arguments passed to the vector store creation (e.g., name, expires_after).
Returns
OpenAIStore- A newly created store instance.
retrieve()
Retrieve the most similar chunks to the given text.
Usage
retrieve(text, top_k, *, attributes_filter=None, **kwargs)Parameters
text: str-
The query text to search for.
top_k: int-
The maximum number of chunks to return.
attributes_filter: Optional[AttributeFilter] = None-
Optional attribute filter as SQL-like string or dict AST. Supports declared attributes only. Built-in columns such as
originare not available in OpenAI filters. **kwargs-
Additional arguments passed to OpenAI’s
vector_stores.search().
Returns
Sequence[RetrievedOpenAIMarkdownChunk]- The retrieved chunks with their relevance metrics.