Add contextual location grounding

This commit is contained in:
2026-08-08 14:49:08 +00:00
parent 8e680cf96e
commit fc76805075
5 changed files with 399 additions and 10 deletions

View File

@@ -31,6 +31,7 @@ type Registry struct {
canonical []byte
digest string
projectionDigest string
identityDigest string
promptInput contracts.LLMInputMaterial
lookupByID map[string]int
}
@@ -105,6 +106,7 @@ func emptyRegistry() *Registry {
list: dnd.LocationRegistry{Locations: []dnd.Location{}},
canonical: append([]byte(nil), content...),
projectionDigest: projectionDigest,
identityDigest: projectionDigest,
promptInput: contracts.NewLLMInputMaterial(ReferenceSlot, locationcodec.MediaType, content, projectionDigest, ""),
lookupByID: map[string]int{},
}
@@ -129,7 +131,7 @@ func loadRegistry(referenceContent []byte) (*Registry, error) {
for index, location := range list.Locations {
lookupByID[location.ID] = index
}
projection, err := promptProjection(list)
projection, err := identityProjection(list)
if err != nil {
return nil, fmt.Errorf("encode location prompt projection: %w", err)
}
@@ -141,6 +143,7 @@ func loadRegistry(referenceContent []byte) (*Registry, error) {
canonical: append([]byte(nil), content...),
digest: digest,
projectionDigest: projectionDigest,
identityDigest: projectionDigest,
promptInput: contracts.NewLLMInputMaterial(ReferenceSlot, locationcodec.MediaType, projection, projectionDigest, ""),
lookupByID: lookupByID,
}, nil
@@ -191,6 +194,15 @@ func (r *Registry) ProjectionDigest() string {
return r.projectionDigest
}
// IdentityDigest returns the digest of the ordered ID/name identity projection
// used by deterministic consumers.
func (r *Registry) IdentityDigest() string {
if r == nil {
return ""
}
return r.identityDigest
}
// Count returns the number of validated location records.
func (r *Registry) Count() int {
if r == nil {
@@ -200,7 +212,8 @@ func (r *Registry) Count() int {
}
// PromptInput returns the ordered ID-and-name projection without evidence or
// reference provenance.
// reference provenance. It remains available only while the location occurrence
// extractor transitions to contextual grounding.
func (r *Registry) PromptInput() contracts.LLMInputMaterial {
if r == nil {
return contracts.LLMInputMaterial{}
@@ -231,19 +244,19 @@ func semanticDigest(content []byte) string {
return "sha256:" + hex.EncodeToString(sum[:])
}
type projectedLocation struct {
type identityProjectedLocation struct {
ID string `json:"id"`
Name string `json:"name"`
}
type projectedLocationRegistry struct {
Locations []projectedLocation `json:"locations"`
type identityProjectedLocationRegistry struct {
Locations []identityProjectedLocation `json:"locations"`
}
func promptProjection(list dnd.LocationRegistry) ([]byte, error) {
projection := projectedLocationRegistry{Locations: make([]projectedLocation, len(list.Locations))}
func identityProjection(list dnd.LocationRegistry) ([]byte, error) {
projection := identityProjectedLocationRegistry{Locations: make([]identityProjectedLocation, len(list.Locations))}
for index, location := range list.Locations {
projection.Locations[index] = projectedLocation{ID: location.ID, Name: location.Name}
projection.Locations[index] = identityProjectedLocation{ID: location.ID, Name: location.Name}
}
return json.Marshal(projection)
}